如何使用xamarin表单中的httpclient获取JSON字符串 [英] How to get the JSON string by using httpclient in xamarin forms

查看:345
本文介绍了如何使用xamarin表单中的httpclient获取JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用httpclient获取json响应我的代码就像

Hi, how to get json response using httpclient my code is like

var client = new HttpClient();
        client.BaseAddress = new Uri(strURL);
        string jsonData=@"{""strUser"":""AS"",""strPassword"":""SA"",""iCompanyId"" : ""108"", ""sMachineName"" : """"}";
        var content = new StringContent(jsonData,Encoding.UTF8,"application/json");
        HttpResponseMessage response=Task.Run(async()=>awaitclient.GetAsync(strURL)).Result;
        var result = await response.Content.ReadAsStringAsync();



它显示StatusCode:405,ReasonPhrase:'方法不允许'例外。否则有任何方法可以获得响应。

谢谢。



我尝试过:




it is showing "StatusCode: 405, ReasonPhrase: 'Method Not Allowed'" exception.Otherwise is there any way to get the response.
Thank you.

What I have tried:

var client = new HttpClient();
        client.BaseAddress = new Uri(strURL);
        string jsonData=@"{""strUser"":""AS"",""strPassword"":""SA"",""iCompanyId"" : ""108"", ""sMachineName"" : """"}";
        var content = new StringContent(jsonData,Encoding.UTF8,"application/json");
        HttpResponseMessage response=Task.Run(async()=>awaitclient.GetAsync(strURL)).Result;
        var result = await response.Content.ReadAsStringAsync();

推荐答案

405 - 方法不允许,意思是你发送了一个服务器未配置处理的HTTP命令...

当您使用GetAsync()时,方法是GET ...检查服务器的OPTIONS以查看允许的内容...

它当然可能是您从未传递的数据(内容?)的问题......
"405 - Method not allowed", means you sent an HTTP command that the server not configured to handle...
As you are using GetAsync(), the method is GET... Check your server's OPTIONS to see what allowed...
It of course can be a problem with the data you never pass on (content?) too...


这篇关于如何使用xamarin表单中的httpclient获取JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆