c# - Can't Download Json Array Windows phone -
i can download json array in windows 8 following code:
astring = "http://website.com/image/image_manifest.json";
private async void getjson(string astring) { var client = new httpclient(); var lresponse = await client.getstringasync(astring); }
this works 100%
i attempting same in windows phone
private void getjson(string anasaurl) { webclient webclient = new webclient(); webclient.downloadstringcompleted += new downloadstringcompletedeventhandler(webclienthandler); webclient.downloadstringasync(new uri(astring)); } private void webclienthandler(object sender, downloadstringcompletedeventargs e) { var lresponse = e.result; }
this not work, receive exception:
an exception of type 'system.reflection.targetinvocationexception' occurred in system.ni.dll not handled in user code
going inner exception see this:
innerexception {system.net.webexception: remote server returned error: notfound. ---> system.net.webexception: remote server returned error: notfound.
full exception below.
edit: httpclient class not available windows phone. chose webclient per interwebs suggestion. open other options. await method doesn't seem work , webclient must called async. think may have conversion of string uri. unfortunately url can't yet made public here similar url structure string.
edited clarity......
> - e {system.net.downloadstringcompletedeventargs} system.net.downloadstringcompletedeventargs + base {system.net.downloadstringcompletedeventargs} system.componentmodel.asynccompletedeventargs {system.net.downloadstringcompletedeventargs} - result 'e.result' threw exception of type 'system.reflection.targetinvocationexception' string {system.reflection.targetinvocationexception} - base {system.reflection.targetinvocationexception: exception occurred during operation, making result invalid. check innerexception exception details. ---> 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) --- end of inner exception stack trace --- @ system.componentmodel.asynccompletedeventargs.raiseexceptionifnecessary() @ system.net.downloadstringcompletedeventargs.get_result()} system.exception {system.reflection.targetinvocationexception} + data {system.collections.listdictionaryinternal} system.collections.idictionary {system.collections.listdictionaryinternal} helplink null string hresult -2146232828 int - 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} + [system.net.webexception] {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.net.webexception + data {system.collections.listdictionaryinternal} system.collections.idictionary {system.collections.listdictionaryinternal} helplink null string hresult -2146233079 int - innerexception {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)} system.exception {system.net.webexception} + [system.net.webexception] {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)} system.net.webexception + data {system.collections.listdictionaryinternal} system.collections.idictionary {system.collections.listdictionaryinternal} helplink null string hresult -2146233079 int + innerexception null system.exception message "the remote server returned error: notfound." string source "system.windows" string stacktrace " @ system.net.browser.clienthttpwebrequest.internalendgetresponse(iasyncresult asyncresult)\r\n @ system.net.browser.clienthttpwebrequest.<>c__displayclasse.<endgetresponse>b__d(object sendstate)\r\n @ system.net.browser.asynchelper.<>c__displayclass1.<beginonui>b__0(object sendstate)" string + static members + non-public members message "the remote server returned error: notfound." string source "system.windows" string stacktrace " @ system.net.browser.asynchelper.beginonui(sendorpostcallback beginmethod, object state)\r\n @ system.net.browser.clienthttpwebrequest.endgetresponse(iasyncresult asyncresult)\r\n @ system.net.webclient.getwebresponse(webrequest request, iasyncresult result)\r\n @ system.net.webclient.downloadbitsresponsecallback(iasyncresult result)" string + static members + non-public members message "an exception occurred during operation, making result invalid. check innerexception exception details." string source "system" string stacktrace " @ system.componentmodel.asynccompletedeventargs.raiseexceptionifnecessary()\r\n @ system.net.downloadstringcompletedeventargs.get_result()" string + static members + non-public members