基本認証を使用するREST WebサービスでXML文字列を返します。 XMLをRestサービスに送信する際に問題が発生する
var req = (HttpWebRequest)WebRequest.Create(uri);
String readToEnd;
const string postData = "";
var encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);
req.Method = "POST";
req.Timeout = 10000;
req.ContentType = "text/XML";
req.ContentLength = byte1.Length;
string authInfo = userName + ":" + password;
authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));
req.Headers["Authorization"] = "Basic " + authInfo;
var newStream = req.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
try
{
var resp = req.GetResponse();
var answer = resp.GetResponseStream();
var _answer = new StreamReader(answer);
readToEnd = _answer.ReadToEnd();
answer.Close();
}
catch (Exception ex)
{
readToEnd = null;
}
return readToEnd != null ? XDocument.Parse(readToEnd) : null;
今すぐ後に、私はそのXMLを操作していると私は戻って別のURIにそれを投稿する準備ができています:ここで私は、データを取得するために使用してXDocumentとしてそれを返す方法があります。私はおそらく、新しいXML文字列を変数 'postData'に入れることを除いて、同じコードになると思います。
xml文字列をWebサービスに投稿する正しい方法ですか?私は見てきましたが、基本的な認可が使用されているときは、このことについて何も言わないようです。
質問の署名についてのよくある質問をご覧ください。 –
あなたは実際に発生した問題を述べることに失敗しました。詳しく教えてください。 –
宜しければ、私は両方の問題に対処しました。 – Jason