[英]C# REST Webclient input type
我已經編寫了一個小應用程序來測試與我編寫的Web服務的連接。 我的問題是,我不知道top如何更改輸入類型的名稱。
我的Web服務看起來像這樣
if ($_FILES["datei"]["error"] == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["datei"]["tmp_name"];
$name = $_FILES["datei"]["name"];
move_uploaded_file($tmp_name, $this->uploads_dir."$name");
return $this->uploads_dir.''.$name;
}
我可以從網絡瀏覽器中調用它,一切正常。
<form action="index.php?action=upload" method="post" enctype="multipart/form-data">
<input type="file" name="datei"><br>
<input type="submit" value="Hochladen">
</form>
但是如果我從我的C#代碼中嘗試它,將變得困難
public static void UploadFilesToRemoteUrl(string url, string datei)
{
System.Net.ServicePointManager.Expect100Continue = false;
WebClient wc = new WebClient();
byte[] arr = wc.UploadFile(url,"post",datei);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string sr = enc.GetString(arr);
MessageBox.Show(sr);
}
上面的代碼無法直接運行。 我發現當我將<input type="file" name="datei">
更改為< input type="file" name="file">
,它將起作用。
在這里,我的問題可以解決C#中的此問題,從而不必更改PHP代碼嗎?
我認為這是一個非常簡單的問題,但是我對Web開發並不那么熟悉,謝謝。
我建議您使用提琴手( http://fiddler2.com/ )查看您通過網絡發送的內容。 您應該比較瀏覽器發送的消息(工作正常)和C#中測試應用程序發送的消息。
一旦知道HTTP消息的哪個文件是錯誤的,就可以嘗試在wc對象中更正它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.