我正在执行HttpWebRequest来执行POST方法。我只有在传递值时才会出错,否则它会完美运行。
代码:
public void CreateOrganization(string accountname)
{
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "POST";
string parsedContent = "{\"name\":\" "+accountname+" \"}";
ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(parsedContent);
Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
}
它停止在Stream newStream = http.GetRequestStream(); 。