Difference between RestSharp methods AddParameter and AddQueryParameter using HttpGET

前端 未结 2 731
抹茶落季
抹茶落季 2021-02-18 17:55

I\'m using RestSharp to call an external API.

This works:

var client = new RestClient(apiUrl);
var request = new RestRequest(myurl, Method.GET);

foreach         


        
2条回答
  •  余生分开走
    2021-02-18 18:32

    To answer your question

    AddQueryParameter adds a parameter in the query string as ParameterType.QueryString whereas AddParameter(string, object) adds the parameter as ParameterType.GetOrPost

    For more details on each parameter type, see:

    GetOrPost: https://github.com/restsharp/RestSharp/wiki/ParameterTypes-for-RestRequest#getorpost

    QueryString: https://github.com/restsharp/RestSharp/wiki/ParameterTypes-for-RestRequest#querystring

    To solve your problem

    It seems it is unrelated to the type of parameter, because the exception thrown seems to indicate you aren't even connecting to the remote server.

    make sure you pass the same apiUrl / myUrl in both cases.

提交回复
热议问题