c# - Base64 String HTTP Post -


this last 2 questions merged one.
i'm building app in xamarin studio ios using monotouch (c#) php http post backend.

on adding feature allow users upload own images have convert image object base64 string save in php.

process:
uiimage -> nsdata -> byte[] -> base64 string -> http post -> decode base64 string -> imagecreatefromstring -> imagejpeg save in php

here source use in c#

public async void post (string uid, string imagebase = null)     {         string data = "";         if (imagebase != null) {             data = string.format ("method=post&uid={0}&image={1}", uid, imagebase);         }          httpwebrequest r = await info.createrequest (data);         using (var resp = await task.factory.fromasync<webresponse> (r.begingetresponse, r.endgetresponse, null)) {             return;         }     }  public static async task<httpwebrequest> createrequest (string json)     {         (new cancellationtokensource ()).dispose ();         var request = webrequest.create (baseurl) httpwebrequest;          request.method = "post";             request.contenttype = "application/x-www-form-urlencoded";          byte[] postdata = encoding.utf8.getbytes (json);         using (var stream = await task.factory.fromasync<stream> (request.begingetrequeststream, request.endgetrequeststream, request)) {             await stream.writeasync (postdata, 0, postdata.length);         }          return request;     } 

here source use in php

imagejpeg(imagecreatefromstring(base64_decode($_post["image"], true)), "users/images/".$_post["uid"]."/".md5(uniqid()).".png"); 

when take imagebase string c# code , manually paste php code replace $_post["image"], works fine. sends on corrupted image stream, can imagine because postdata encoded using utf8, , when it's decoded on server side, not handle, isn't decoded correctly.

going try use plain/text http post didn't seem help, out of mad worse.

it fixed using webutility.urlencode on baseimage string.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -