简体   繁体   中英

C# REST Webclient input type

i've wrote a small application to test a connection to a webservice i wrote. My problem is, that i don't know how top change the name of an input type.

My Webservice looks something like that

    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

    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.

Here my question can i solve this problem in C# so that i don't have to change the PHP code ?

I think this is a very easy question but i am not so familiar with webdevelopment Thanks in advance.

I would recommend you to use fiddler ( http://fiddler2.com/ ) to view what are you sending exactly over the wire. You should compare the messages sent by the browser (which works fine) and the message sent by your test app in C#.

Once you know which filed of the HTTP message is wrong, you can try to correct it in the wc object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM