![](/img/trans.png)
[英]How to upload file to server with HTTP POST multipart/form-data?
[英]How to use multipart/form-data post method to upload an instance of an object to a server REST?
我在論壇上搜索它,我嘗試了所有可能的解決方案,但這對我沒有任何作用。 我有一個對象Utente轉換為byte []和json字符串(我不知道我必須發送哪一個)。 這是我必須發送的對象:
public class Utente
{
public string name { get; set; }
public string lastname { get; set; }
public int id { get; set; }
public int issuperuser { get; set; }
public string persontype { get; set; }
public int idpersontype { get; set; }
public string token { get; set; }
public string[] permissions { get; set; }
public List<Mese> mese { get; set; }
}
我試着這樣做
void Upload(string k)
{
AppSettingsReader settings = new AppSettingsReader();
string URL = settings.GetValue("BasePath", typeof(string)).ToString() + settings.GetValue("MesePath", typeof(string)).ToString();
WebRequest richiesta = (HttpWebRequest)WebRequest.Create(URL);
WebResponse risposta = (HttpWebResponse)Makerequest(richiesta).GetResponse();
}
private WebRequest Makerequest(WebRequest request)
{
request.ContentType = "multipart/form-data";
request.Method = "POST";
request.Headers.Add("X-Auth-Token", Utente.Instance.token + "|Desktop");
request.ContentLength = 0;
return request;
}
但它不起作用,所以我隨機寫代碼試圖做一些事情...我從來沒有使用'k',但它是對象的Uson字符串Utente可以有人幫助我嗎? 至少解釋如何使用multipart / form-data謝謝!
我認為您首先需要了解multipart / form-data。 您可以在此處執行此操作: https : //www.w3.org/TR/html401/interact/forms.html#h-17.13.4就您的問題而言,您可以執行簡單的REST調用以將數據上傳到服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.