Answered post query string in api

Bilal bouker

New member
Joined
Sep 13, 2020
Messages
1
Programming Experience
1-3
Hi everyone

I have a program desktop called API used httpclient

this API => jomla_sandbox


all URL it's working (post ,get ) but this

POST
Sandbox-Secure Voucher
==> jomla_sandbox
I have problem because is accepts param in the header I try all code when I know or find after serach but it's not working.


unnamed.png

this some code when I'm trying:

======CODE 1=========
client.BaseAddress = new Uri(uri);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Properties.Settings.Default.TOKEN);
client.DefaultRequestHeaders.Accept.Add( Add("product_id", "6");
HttpResponseMessage response = await client.PostAsJsonAsync("api/voucher");
return reports = await response.Content.ReadAsAsync<Voucher>();

======CODE 2=========

var clientr = new RestClient("https://jomla-api-sandbox.kushok.com:8802/index.php/api/vouche/secure?product_id=6");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter(("product_id", 6);
IRestResponse response = clientr.Execute(request);
var result = response.Content;

=====================

please any one can help me
 
Token from settings like in your code:
C#:
var client = new RestClient("https://jomla-api-sandbox.kushok.com:8802/index.php/api");
var request = new RestRequest("voucher/secure", Method.POST);
request.AddHeader("Authorization", $"Bearer {Properties.Settings.Default.TOKEN}");
request.AddParameter("product_id", "6");
var response = client.Execute(request);
 
Don't be one of those wannabe developers who looks up code to use, without knowing how it works or what it does. That's why documentation exists, and that's the first place you should have gone before asking on a public forum.

If you have 1,3 years programming experience, you should be smart enough to know to visit and read the documentation by the language providers website you are using for what you're trying to do.
 
Back
Top Bottom