我使用Xamarin Forms并对API进行休息调用,我是新手。我想发送我的搜索参数:
{ "busObIds": [
"8102508"], "searchText": "John"}
(这是原始JSON格式)到API端点:
var client = new RestClient("http://localhost/NameAPI/api/V1/getquicksearchresults");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer " + bearer);
我还有一个需要申请的授权持有人。我绊倒了这个并不确定如何正确地做到这一点,因为我在Postman中展示了如何做但目前无法将其转换为我在Visual Studio Xamarin Forms中的项目。如果可以,请帮忙。
无论如何,提前谢谢你。
更新:
var _client = new RestClient("http://localhost/NameAPI/api/V1/getquicksearchresults");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "Bearer " + bearer);
request.AddParameter("busObIds", "8102508");
request.AddParameter("searchText", "John");
IRestResponse response = _client.Execute(request);
var jsonData = response.Content;
var jsonObj = JsonConvert.DeserializeObject<CiResponse>(jsonData);
this.CiList = new ObservableCollection<CiItem>();
if (null != jsonObj && jsonObj.Types != null && jsonObj.Types.Count > 0)
{
foreach (var item in jsonObj.Types)
this.CIList.Add(new CiItem
{
PublicId = item.PublicId,
SubTitle = item.SubTitle,
Text = item.Text,
Title = item.Title
});
}
在跑步时,我没有迹象表明它不正确,但屏幕上没有显示输出。