0

Currently trying to upload image to database through uri. for that i am using HttpClient class. But it shows path too long exception.(because i convert the image to base64 string and upload it). I tried to insert through WebClient class but unfortunately WebClient class is not available in uwp. so how do i upload the image through uri??

Code

    public async void Upload()
    {

        var url1 = "http://www.example.com/upload.php";
        var values1 = new List<KeyValuePair<String, String>>
        {

             new KeyValuePair<string, string>("Date", x.Date.ToString()),
             new KeyValuePair<string, string>("Bill_Image", x.Bill_Image.ToString()),

         };
             HttpClient client1 = new HttpClient();
             HttpResponseMessage response1 = new HttpResponseMessage();

             try
             {
                response1 = await client1.PostAsync(url1,new FormUrlEncodedContent(values1));

                    if (response1.IsSuccessStatusCode)
                    {
                        var dialog = new MessageDialog("Successfully Added");
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        // problems handling here
                    }
              }
              catch (Exception exc)
              {
                  Debug.WriteLine(exc.ToString());
              }
      }
Manikandan
  • 15
  • 7
  • The PostAsync call looks OK. Which line exactly do you get the exception? – Clemens Dec 15 '16 at 08:48
  • In the PostAsync line itself.. "response1 = await client1.PostAsync(url1,new FormUrlEncodedContent(values1));" – Manikandan Dec 15 '16 at 09:34
  • Possible duplicate of [How to pass long string in HttpClient.PostAsync request](http://stackoverflow.com/questions/35047048/how-to-pass-long-string-in-httpclient-postasync-request) – AVK Dec 15 '16 at 16:04
  • It seems that `FormUrlEncodedContent` has constants limiting the size of request length. Instead, you can try to use `StringContent` It actually is HttpContent. – Xie Steven Dec 16 '16 at 05:59
  • i tried to do with your references. but it seems to be working.. but the database row value is empty..why so?? – Manikandan Dec 16 '16 at 08:36
  • @Manikandan You could use fildder to capture data in your client and server. If your server get data successfully. I’m afraid this issue was due to your database. – Xie Steven Dec 19 '16 at 05:36
  • okay.. let me try.. i have json object in c#. How do i capture this json object in php file?? have any idea regarding that?? – Manikandan Dec 19 '16 at 09:24
  • @Manikandan Please check [Fiddler document](http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureFiddler) to learn how to use it. – Xie Steven Dec 21 '16 at 08:49
  • Found the solution.. Used the Windows.Web.Http.HttpClient. And used HttpFormUrlEncodedContent instead of FormUrlEncodedContent.. And that got successfully inserted. – Manikandan Jan 02 '17 at 10:56

0 Answers0