0
我使用HttpWebRequest for Multipart Post將圖像以字節數組的形式上傳到服務器,我應該收到一個包含帖子細節的json字符串作爲響應。但與此相反,無論郵件是否成功,我都會收到響應代碼「OK」作爲迴應。有人能幫我解決這個問題嗎?多部分帖子的問題
我使用以下代碼的帖子。
Dictionary<string, object> postParam;
public void SubmitPost()
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(new Uri(url, UriKind.Absolute));
myRequest.Method = "POST";
myRequest.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest);
}
public string url
{
get
{
return "URL";
}
}
string boundary = "----------" + DateTime.Now.Ticks.ToString();
private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
writeMultipartObject(postStream, postParam);
postStream.Close();
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
string res;
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
streamResponse.Close();
streamRead.Close();
res = response.StatusCode.ToString();
response.Close();
}
資源的價值始終是 「OK」
thanx @ Ku6opr ...它的工作 – 2012-01-12 12:07:11