0
votes

I'm really stuck to send a POST request by HttpClient with Parameters:

    private async Task<string> PostAsync(string parameterValue)
    {
        var ResponseMessage = await HttpClient.PostAsyncAsync(myUri, new FormUrlEncodedContent(
            new[]
            {
                new KeyValuePair<string, string>("parameter", parameterValue)

Thanks - })); var httpResponse = await Deserialize(ResponseMessage);

        return Response.Token;
    }

What I get is POST https://URI with parameters in the content HTTP/1.1 and what I need is https://URI?parameter=PARAMETERVALUE HTTP/1.1

Can anybody help me?

EDIT:

Thanks - It's just like:

    private async Task<string> PostAsync(string parameterValue)
    {
        var ResponseMessage = await HttpClient.PostAsyncAsync(string.Format(myUri?parameter={0}, parameterValue), null)
2
POST doesn't pass the values in the URL. You'll have to use GET instead if you want your parameters in the URL. - diiN__________
I know, but in this case I need to pass variables with a POST - Tom

2 Answers

1
votes

The method you are using takes everything in the 2nd parameter and uses it for HttpContent. You can read more here. What you should be doing is appending the parameters to myUri variable.

0
votes

You shouldn't be passing values in the URL, this likely goes into an encoded body section (accessible via the request stream of an HttpWebRequest). I would suggest a tool such as Fiddler in order to analyze the type of POST request you are trying to make, so that you will know what kind of data needs to go into the body, the encoding type, protocols, etc.