[英]C# REST Webclient input type
i've wrote a small application to test a connection to a webservice i wrote. 我已经编写了一个小应用程序来测试与我编写的Web服务的连接。 My problem is, that i don't know how top change the name of an input type. 我的问题是,我不知道top如何更改输入类型的名称。
My Webservice looks something like that 我的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;
}
I can call it from the webbrowser and everything works fine. 我可以从网络浏览器中调用它,一切正常。
<form action="index.php?action=upload" method="post" enctype="multipart/form-data">
<input type="file" name="datei"><br>
<input type="submit" value="Hochladen">
</form>
But if i try it from my c# code it gets difficult 但是如果我从我的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);
}
The code above doesn't work directly. 上面的代码无法直接运行。 i figured out that when i change <input type="file" name="datei">
to < input type="file" name="file">
it will work. 我发现当我将<input type="file" name="datei">
更改为< input type="file" name="file">
,它将起作用。
Here my question can i solve this problem in C# so that i don't have to change the PHP code ? 在这里,我的问题可以解决C#中的此问题,从而不必更改PHP代码吗?
I think this is a very easy question but i am not so familiar with webdevelopment Thanks in advance. 我认为这是一个非常简单的问题,但是我对Web开发并不那么熟悉,谢谢。
I would recommend you to use fiddler ( http://fiddler2.com/ ) to view what are you sending exactly over the wire. 我建议您使用提琴手( http://fiddler2.com/ )查看您通过网络发送的内容。 You should compare the messages sent by the browser (which works fine) and the message sent by your test app in C#. 您应该比较浏览器发送的消息(工作正常)和C#中测试应用程序发送的消息。
Once you know which filed of the HTTP message is wrong, you can try to correct it in the wc object. 一旦知道HTTP消息的哪个文件是错误的,就可以尝试在wc对象中更正它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.