POST request with parameters [duplicate]
Clash Royale CLAN TAG#URR8PPP
POST request with parameters [duplicate]
This question already has an answer here:
I need to send a POST request with body parameters. I already know how to send post requests with a body, but I don't know (if exists) the relation between body and body parameters. I tried searching but it seems everything I find forces me to replace HttpClient to some other service and I don't know what it involves.
I need to set two parameters, in postman: Param1:guid
, Param2:0
Param1:guid
Param2:0
My code:
public async Task MarkCustomerGuid(string guid,int id)
HttpResponseMessage response;
string json = "";
using (var client = new HttpClient())
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
Encoding.ASCII.GetBytes(
string.Format("0:1", "XX", "YY"))));
string url = "https:XXX" + id + "@gmail.com&linkclicked1=1";
//I'm sending an empty body for now. Should it be on the body?
// Or are there properties for this?
response = await client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
json = await response.Content.ReadAsStringAsync();
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@Crowcoder Yes. I am .
– Yossi
Aug 8 at 14:04
@Adriani6 Looks good, I'll test it .
– Yossi
Aug 8 at 14:04
1 Answer
1
I am not sure if this is what you mean:
var url = $"https://XXXid@gmail.com&linkclicked1=1"
var parameters = new Dictionary<string, string> "param1", "value" , "param2", "value" ;
var encodedContent = new FormUrlEncodedContent (parameters);
var response = await HttpClient.PostAsync (url, encodedContent).ConfigureAwait (false);
Are you sure that is not supposed to be a GET request? You don't usually see query string parameters in POST.
– Crowcoder
Aug 8 at 14:03