當我試圖上傳文件Box Storage
使用框,但在響應時間,我收到此錯誤無法使用此動詞類型發送內容主體。而得到錯誤的反應時,試圖上傳文件箱收納
public static void UploadFileRequest(string FolderID, string accesstoken)
{
string boundary = string.Format("----------------------------{0}", DateTime.Now.Ticks.ToString("x"));
string filename="C:\\Users\\Administrator\\Desktop\\Text.txt";
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("https://upload.box.com/api/2.0/files/content");
ASCIIEncoding encoding = new ASCIIEncoding();
string hh = "\"[email protected]\"" + filename + "\" "+";"+"";
hh += "parent_id=\"" + FolderID + "\"";
string kj = string.Format(("[email protected]" + filename));
byte[] data = encoding.GetBytes(hh);
httpWReq.Headers.Add("Authorization", "Bearer " + accesstoken);
httpWReq.ContentType = "application/json";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
弗雷德裏克你是對的,我錯過了POST方法有..但對我來說還是沒有反應。我認爲體格格式存在問題。 – user3463612
獲取錯誤的響應(400),某處做錯誤在正文 串bodymessage =的String.Format( 「文件名= @ {0}&PARENT_ID = {1}」,文件名,FolderID); byte [] data = encoding.GetBytes(bodymessage); //獲得在下面線路錯誤的StreamReader(response.GetResponseStream())ReadToEnd的(); } – user3463612
你是否在調用'GetResponse()'之前將你的字節寫入請求流? –