c# - Problems using Mashape API in .NET -


i found great code on net using mashape api qr code. here.

their code works great, if try , change use mashape,

"an exceptions occured during operation, making result invalid"

error. , checking inner exception.

code below shows qr code link , goes @ trying use weather api , spotify api.

private void button_click(object sender, routedeventargs e) {     webclient client = new webclient();     client.uploadstringcompleted += new uploadstringcompletedeventhandler(client_uploadstringcompleted);     client.headers[httprequestheader.contenttype] = "application/x-www-form-urlencoded";     client.headers["x-mashape-authorization"] = "mashape-api-code-goes-here";      stringbuilder postdata = new stringbuilder();     // spotify (this doesn't work)     // postdata.appendformat("{0}={1}", "q", httputility.urlencode(txtartitst.text));     // var uri = new uri("https://mager-spotify-web.p.mashape.com/search/1/artist.json?", urikind.absolute);      // weather info (this doesn't work)     postdata.appendformat("{0}={1}", "_method", httputility.urlencode("getforecasts"));     postdata.appendformat("&{0}={1}", "location", httputility.urlencode("brisbane"));     var uri = new uri("https://george-vustrey-weather.p.mashape.com/api.php?", urikind.absolute);      // qr code (this works)     //postdata.appendformat("{0}={1}", "content", httputility.urlencode("testqrcode"));     //postdata.appendformat("&{0}={1}", "quality", httputility.urlencode("l"));     //postdata.appendformat("&{0}={1}", "type", httputility.urlencode("text"));     //postdata.appendformat("&{0}={1}", "size", httputility.urlencode("5"));     //var uri = new uri("https://mutationevent-qr-code-generator.p.mashape.com/generate.php?", urikind.absolute);      client.uploadstringasync(uri, "post", postdata.tostring());     txtresult.text = postdata.tostring();      progress1.isindeterminate = true;     button1.isenabled = false; }   void client_uploadstringcompleted(object sender, uploadstringcompletedeventargs e) {     progress1.isindeterminate = false;      var client = sender webclient;     client.uploadstringcompleted -= client_uploadstringcompleted;     string response = string.empty;     if (!e.cancelled)     {         try         {             response = httputility.urldecode(e.result);  // seems error out here - result invalid             txtresult.text = response;         }         catch (exception ex)         {             txtresult.text = "error : " + ex.message;         }     }      button1.isenabled = true; } 

the inner exception says :

innerexception

    {system.net.webexception: remote server returned error: notfound. ---> system.net.webexception: remote server returned error: notfound.    @ system.net.browser.clienthttpwebrequest.internalendgetresponse(iasyncresult asyncresult)    @ system.net.browser.clienthttpwebrequest.<>c__displayclasse.<endgetresponse>b__d(object sendstate)    @ system.net.browser.asynchelper.<>c__displayclass1.<beginonui>b__0(object sendstate)    --- end of inner exception stack trace ---    @ system.net.browser.asynchelper.beginonui(sendorpostcallback beginmethod, object state)    @ system.net.browser.clienthttpwebrequest.endgetresponse(iasyncresult asyncresult)    @ system.net.webclient.getwebresponse(webrequest request, iasyncresult result)    @ system.net.webclient.downloadbitsresponsecallback(iasyncresult result)}   system.exception {system.net.webexception} 

did try instead of post?

also, can try application/json instead of application/x-www-form-urlencoded

a working example on windows 8 here - https://github.com/ismaelc/mashape_windows8_sample/blob/master/app5/app5/mainpage.xaml.cs


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -