Data Submit post, get
Public stringWebclientpost (stringPostData,stringPostURL,stringType) { stringPoststring =PostData; byte[] PostData = Encoding.UTF8.GetBytes (poststring);//coding, especially Chinese characters, in advance to see how to crawl the page encoding stringurl = posturl;//AddressWebClient WebClient =NewWebClient (); byte[] ResponseData =NULL; if(Type = ="Post") {WEBCLIENT.HEADERS.ADD ("Content-type","application/x-www-form-urlencoded");//To take the post must be added to the header, if you change to get a way to remove this sentence can beresponsedata = Webclient.uploaddata (URL,"POST", PostData);//get a stream of returned characters } Else{responsedata= Webclient.uploaddata (URL,"GET", PostData);//get a stream of returned characters } stringsrcstring = Encoding.UTF8.GetString (responsedata);//decoding returnsrcstring; }
File parsing
1 Convert to jobject
string_result = PostData (Appid, AppKey, IMGSRC,"","Post"); Jobject Jsondata=Jobject.parse (_result); Jarray Jsonface= Jsondata.getvalue (" Face") asJarray; if(Jsonface = =NULL) {msg="Err"+","+"format is not correct"; } Else { intHeight =0; intwidth =0; intcenter_x =0; intCenter_y =0; stringSex =""; if(Jsonface! =NULL&& Jsonface.count >0) {Height=int. Parse (jsonface[0]["position"]["Height"]. ToString ()); Width=int. Parse (jsonface[0]["position"]["width"]. ToString ()); Center_x=int. Parse (jsonface[0]["position"]["Center"]["x"]. ToString ()); Center_y=int. Parse (jsonface[0]["position"]["Center"]["y"]. ToString ()); Sex= jsonface[0]["attribute"]["Gender"]. ToString (); }
}
2 Dictionary
dictionary<stringobject> Objjson = jsonconvert.deserializeobject<dictionary< StringObject>>(request); string state = objjson["State"]. ToString ();
Data download
stringIMGSRC = context. request.form["Imgurl"]. ToString ();//Server ConnectionstringFiledir ="/publicresource/"; stringAppName = system.configuration.configurationmanager.appsettings["AppName"]; if(!string. IsNullOrEmpty (AppName)) {Filedir="/publicresource/"+ AppName +"/"; } Guid NewId=Guid.NewGuid (); WebClient WC=NewWebClient (); stringWxpath = context. Server.MapPath (Filedir + newid.tostring () +". jpg"); Wc. DownloadFile (IMGSRC, wxpath);
WebClient data transfer