error while sending data containing commas

hello,
I'm sending data using THttpClient with content-type application / x-www-form-urlencoded. In one of the data parameters there is a comma symbol character. this results in a Bad request. Please inform to send the correct data if referring to my code, the following parameter name contains commas.

  FClient := THttpClient.Create;
  FClient.OnSendingRequest := procedure(Req: THttpRequest)
    begin
      Req.Headers.SetValue('content-type', 'application/x-www-form-urlencoded');
      Req.Headers.SetValue('authorization',
        TSparkleUtils.BasicAuthHeaderValue(key, pass));
    end;
  Req := FClient.CreateRequest;
  try
    //set request method
    ext_id := 'yyywgtd56'; 
    name_cust := 'Wart, Hext, Gorm';   
    Req.Method := 'POST';
    //set uri
    Req.Uri := Url_Client + PathClient;
    //set data
    sData := 'ext_id='+ext_id+'&name_cust='+name_cust;

    Req.SetContent(TEncoding.UTF8.GetBytes(sData));

    Resp := FClient.Send(Req);
    //fill response
    Result := TEncoding.UTF8.GetString(Resp.ContentAsBytes);
  finally
    Req.Free;
    Resp.Free;
    FClient .Free;
  end;

Hi. Have you tried using TSparkleUtils.PercentEncode(name_cust)

or

TSparkleUtils.PercentEncode(sData)

Regards,

1 Like

thanks for the suggestion, but I've tried using this. the problem still the same.

:handshake:

1 Like

It would be helpful if you post the exact code you used, then.

I believe this is a 3rd party server? You have to know what are the requirements of such server to send a correct request. I also see you didn't set the content-type header o you request, you should do that as well.

helo wagner,

I'm sorry I was too hasty to conclude, this is indeed a 3rd party server. My code has been running for 3 months and recently had a problem. after I asked the 3rd party server, they said there were changes to the data specifications that the client had to send. the current problem has been resolved.

Thanks you

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.