次の関数で http 投稿をしようとしています。投稿データに通常の JSON データ (テキストのみ) が含まれていても問題なく動作します。しかし今、私のjsonデータには、そのフィールドの1つにxmlも含まれています。
public string postJSON(string username, string password, string endPoint, string json)
{
HttpWebRequest request = CreateWebRequest(endPoint, "POST", "text/json");
request.Credentials = new NetworkCredential(username, password);
try
{
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
}
catch (Exception ex)
{
logger.WriteToLog("RequestMaker", "postJason function: " + ex.Message);
return "error";
}
}
しかし、そうしようとすると、不正な URL エラー (400) が発生します。私のエンドポイント URL は次のよう に なります。
"{\"XMLData\":\"<Subscribers><Subscriber><Name>Pedram</Name><Email>mobedi@live.com</Email><DemographicData><Demographic mapTo='Urval'>30</Demographic></DemographicData></Subscriber><Subscriber><Name>Anders Svensson</Name><Email>pmobedi@yahoo.com</Email><DemographicData><Demographic mapTo='Urval'>27</Demographic></DemographicData></Subscriber></Subscribers>\"}"
他にすべきことはありますか?