restsharp

How to use OAuth2 in RestSharp

﹥>﹥吖頭↗ 提交于 2019-12-02 17:31:59
After a couple of days sorting out OAuth2 at the server-end (Spring java) I started working on the client written in C#. I am using RestSharp to call my web API but I am having real difficulty with the OAuth2. There is hardly any documentation and the few examples I found online do not work. Can someone provide me a code sample that is up to date and that I can use? So far I have the following: var client = new RestClient("http://example.com/myapi/oauth/token"); RestRequest request = new RestRequest() { Method = Method.POST }; request.AddHeader("Content-Type", "application/json"); request

How to make restsharp to work with the right encoding for response?

佐手、 提交于 2019-12-02 11:13:07
I have the same problem like this question RestSharp ignores response charset encoding . But there is no right answer! Code like this IRestResponse RSP = client.Execute(request); not like this Encoding encoding = Encoding.GetEncoding("ISO-8859-1"); var result = encoding.GetString(response.RawBytes); It means the resetsharp must deserializ the result with right encoding. Someone can help? I solved this problem by myshelf you just down the code source from github and edit the code stemp 1: find HttpResponse.cs : stemp 2: find Http.cs , Ohm,maybe this solution is not match you,my request result

Translate cUrl to restsharp

五迷三道 提交于 2019-12-02 09:02:16
I have a cUrl request: curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @C:\nyc_khr.zip http://localhost:9090/geoserver/rest/workspaces/nyc_roads/datastores/roads/file.shp I need make a request like above, but using C# Example of my code: RestClient client = new RestClient(URL) { Authenticator = new HttpBasicAuthenticator("admin", "geoserver") }; var data = File.ReadAllBytes(somePath); string url = @"rest/workspaces/nyc_roads/datastores/roads/finalas.shx"; var request = new RestRequest(url, Method.PUT); request.AddHeader("Content-Type", "application/zip");

Convert pdf file received in string variable to byte array in C#

早过忘川 提交于 2019-12-02 04:29:19
I am trying to develop an application in C# which takes data from Service1(3rd party), processes it and then sends data to Service2(again 3rd party). The data I am trying to receive, process and send is a pdf file From Service1, I am receiving pdf file in a string variable. e.g. response.Content = "%PDF-1.4 \n1 0 obj\n<<\n/Pages 2 0 R\n/Type /Catalog\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [ 3 0 R 17 0 R ]\n/Count 2\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/Resources <<\n/XObject << /Im0 8 0 R >>\n/ProcSet 6 0 R >>\n/MediaBox [0 0 ..." Now, Service2 requires PDF data to be

Silverlight: HTTP DELETE and PUT methods with RestSharp

一笑奈何 提交于 2019-12-01 23:48:16
I wanted to access an internal REST API from Silverlight, but it turns out that I am not allowed to use POST or DELETE as the HTTP method for my request. Doing so always resulted in a SecurityException . What is the recommended way to use REST apis with Silverlight? SecurityException probably means the API doesn't have the proper clientaccesspolicy.xml file in place. Here's an example of a very lenient one that allows all HTTP methods and headers. We have used this successfully for our API (which is popular, though I don't know how much traffic we get from Silverlight). <?xml version="1.0"

RestSharp POST request translation from cURL request

房东的猫 提交于 2019-12-01 21:27:18
I'm trying to make a POST request using RestSharp to create an issue in JIRA, and what I have to work with is an example that uses cURL. I'm not familiar with either enough to know what I'm doing wrong. Here's the example given in cURL: curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/ Here's their example data: {"fields":{"project":{"key":"TEST"},"summary":"REST ye merry gentlemen.","description":"Creating of an issue using project keys and issue type names using the REST API","issuetype":{"name":"Bug"}}} And here's

RestSharp response unauthorized

≡放荡痞女 提交于 2019-12-01 20:55:48
I am new to web based solutions. I am hitting a rest url using RestSharp library. My code is as follows: var cleint = new RestClient("http://REST_URL"); cleint.Authenticator = new HttpBasicAuthenticator("username", "password"); var request = new RestRequest(); request.Method = Method.GET; request.Resource = "0.json"; IRestResponse response = cleint.Execute(request); if (response != null && ((response.StatusCode == HttpStatusCode.OK) && (response.ResponseStatus == ResponseStatus.Completed))) { // var arr = JsonConvert.DeserializeObject<JArray> (response.Content); } The url returns a json file,

Do not encode parameters in RestSharp

自闭症网瘾萝莉.ら 提交于 2019-12-01 19:59:50
I am using RestSharp to access a RubyOnRails API. As you might know, RoR likes when the parameters names are in the form model_name[property] . RestSharp, on the other hand, does not like it. Fiddler says I send this to the server : user%5Bemail%5D=user%40email.com&user%5Bpassword%5D=test It looks like R# encodes both the parameters and values when it sends the data (unlike Curl, which looks like it encodes selectively). While that's fine most of the time I guess, in this particular case, it makes the API return a 401 because it doesn't understand the parameters. Is it possible to ask R# to

RestSharp Serialize/Deserialize Naming Conversion

笑着哭i 提交于 2019-12-01 19:49:53
I am attempting to wrap the Plivo API ( yes I'm aware it's been done ) using RestSharp. However, I cannot find a method to translate the API Naming conventions to my own, for example: A "Call` ( https://www.plivo.com/docs/api/call/#make-an-outbound-call ) requires a minimum of: to , from , and answer_url parameters be provided. These parameters are also case-sensitive. I would like to be able to provide a CallRequest Class, wrapping the data required in my preferred naming conventions, and then somehow translate these prior to serialization by RestSharp. Example: public class CallRequest { ///

RestSharp ignoring system proxy (for example Fiddler) on .NET Core

感情迁移 提交于 2019-12-01 17:18:55
I want check the http traffic with Fiddler, but no any http traffic captured, my testing codes: private static void ByRestSharp() { var restClient = new RestClient("https://jsonplaceholder.typicode.com"); var request = new RestRequest("posts", Method.GET); var response = restClient.Get<List<Post>>(request); Console.WriteLine("{0} posts return by RestSharp.", response.Data.Count); } But after I changed to use HttpClient, Fiddler can capture the http traffic, sample codes: private static void ByHttpClient() { var httpClient = new HttpClient(); using (var req = new HttpRequestMessage(HttpMethod