嗨我想做Http Post請求,但得到錯誤的請求我認爲我做錯了請求中的任何人如果有人可以幫助我。Http發佈請求與Boundry錯誤壞請求
這是請求
POST /uapi/faxes/@me/0003*210 HTTP/1.1
HOST uapi.voipnow.com
Content-Length:469
Content-Type: multipart/form-data; boundary=------------325343636
------------325343636--------
Content-Disposition:form-data; name="files"; filename="/path/to/file/fax.txt"
Content-Type;application/octet-stream
This is my fax
------------325343636
Content-Disposition:form-data; name="request";
{
"recipients":["7778888"]
}
------------3253436360
這是我此請求在recipie供給
try
{
String Token = "mytoken";
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
HttpWebRequest httpWReq2 = (HttpWebRequest)WebRequest.Create("https://domainname/uapi/faxes/@me/0014*100/?accessRequestToken=" + Token);
ASCIIEncoding encoding2 = new ASCIIEncoding();
string postData2 =
"------------325343636" + Environment.NewLine +
"Content-Disposition:form-data; name=\"files\";filename=\"/path/to/file/fax.txt\";" + Environment.NewLine +
"Content-Type:application/octet-stream;" + Environment.NewLine +
"This is my fax" + Environment.NewLine +
"------------325343636" + Environment.NewLine +
"Content-Disposition:form-data; name=\"request\";" + Environment.NewLine +
"{" + Environment.NewLine +
"\"recipients\":[\"111111\"];" + Environment.NewLine +
"}" + Environment.NewLine +
"------------325343636";
byte[] data2 = encoding2.GetBytes(postData2);
httpWReq2.Method = "POST";
httpWReq2.ContentType = "multipart/form-data; boundary=------------325343636";
httpWReq2.KeepAlive = true;
httpWReq2.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17";
httpWReq2.ContentLength =data2.Length;
httpWReq2.Host = "hostname";
string result2 = "";
Stream dataStream2 = httpWReq2.GetRequestStream();
dataStream2.Write(data2, 0, data2.Length);
dataStream2.Close();
WebResponse response2 = httpWReq2.GetResponse();
HttpWebResponse responce3 = (HttpWebResponse)httpWReq2.GetResponse();
dataStream2 = response2.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader2 = new StreamReader(dataStream2);
// Read the content.
string responseFromServer2 = reader2.ReadToEnd();
}
catch (Exception ex)
{
WebException ex2 = (WebException)ex;
if (ex2.Status == WebExceptionStatus.ProtocolError)
{
WebResponse resp = ex2.Response;
using (Stream respstream = resp.GetResponseStream())
{
StreamReader reader = new StreamReader(respstream);
String finalerror = reader.ReadToEnd();
}
}
}
錯誤
值代碼nts參數丟失或無效。 參數必須引用任何電話號碼
你要發送什麼服務器?這是供應商特定的。 – 2013-03-05 17:57:39
@ DanielA.White你好,先生,你說得對,這是供應商特定的。我想知道我的請求中PostData有什麼問題。 – Hiren 2013-03-05 18:00:34
@DiskJunky我認爲內容長度應該與PostData Length相同,我錯了嗎? – Hiren 2013-03-05 18:02:53