0
在我的情况我的API处理JSON阅读它作为邮政JSON数据作为的WebRequest的查询字符串
if (context.Request.Files.Count > 0)
{
jsonData = context.Request.Params["key"];
}
从我的应用程序如何可以发送一个网络请求,这个API没有JSON作为查询字符串参数。正弦Json是冗长的,我知道查询字符串是有限的。
对于android的ios这个api工作正常。
我试图将它添加到标题。但徒劳无益。
我该如何添加它,以便“jsonData = context.Request.Params [”key“];”将得到我的json。 我的请求格式在这里。
urlS="http://abc.ashx?Key="+jsonRequestS;
string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
var webRequest1 = (HttpWebRequest)WebRequest.Create(urlS);
webRequest1.Method = "POST";
webRequest1.KeepAlive = false;
webRequest1.ContentType =string.Format("multipart/form-data; boundary={0}", boundary);//
Stream postDataStream1 = handler.GetPostStream(boundary,jsonRequestS); // Writes boundary and files to memory stream.
webRequest1.ContentLength = postDataStream1.Length;
Stream reqStream1 = webRequest1.GetRequestStream();
postDataStream1.Position = 0;
var bufferBytes = new byte[postDataStream1.Length];
postDataStream1.Read(bufferBytes, 0, bufferBytes.Length);
reqStream1.Write(bufferBytes, 0, bufferBytes.Length);
postDataStream1.Close();
reqStream1.Close();
var sReader = new StreamReader(webRequest1.GetResponse().GetResponseStream());//here Am getting the error.
string resultS = sReader.ReadToEnd();
在此先感谢。
你能提供一个例子,声明要求你会喜欢用?你说你不想把json放在查询字符串中,那么你说你想从查询字符串中读取json。 – 2013-03-07 14:19:32
“jsonData = context.Request.Params [”key“];这是声明在那里读取我的Json数据..我想知道如何发送json到API,以便API可以读取它。但是作为Qry字符串,我可以发送一个冗长的Json,所以我应该使用哪种方法。 – 2013-03-08 04:08:07