Synapse bug? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- BlueIcaro · 2022-04-22 13:19 Hello, I working in a program, which comunique with a server using Get,Post, PUT, etc methods. Using Post method you have to send to a server the Content-Type http header  with value application/x-www- form-urlencoded. There is no problem when you using Post method with Data Parameters. I write in my code before call HTTPMethod: Code: [Select] Fht.MimeType := 'application/x-www-form-urlencoded';  Data Parameters are loaded in Document property of THttpsend object But has some request  usign Post method with out Data Parameters. When I do this, the server returns a error: QuoteUNSUPPORTED_MEDIA(415) The server will not accept the request, because the media type is not supported So I was debuging and I found that sypnase code doesn't add the Content-type Header  if you don't use DataParameter Code: [Select]function THTTPSend.HTTPMethod(const Method, URL: string): boolean // line 387 of httpsend Unit (...)   Sending := FDocument.Size > 0;  (...)   if Sending then   begin     FHeaders.Insert(0, 'Content-Length: ' + IntToStr(InputDocument.Size));     if FMimeType <> '' then       FHeaders.Insert(0, 'Content-Type: ' + FMimeType);   end; This lines is the origin of my problem. So I changed it to: Code: [Select]if Sending then   begin     FHeaders.Insert(0, 'Content-Length: ' + IntToStr(FDocument.Size));   end;   if FMimeType <> '' then   begin     FHeaders.Insert(0, 'Content-Type: ' + FMimeType);   end;      I don't know if this is a bug of Sypnase Library. Because I'm not a expert in HTTP protocol. But After this fix I got a correct answer from server. If this is a bug, any one know how can I report this to author? /BlueIcaro ---------------------------------------------------------------------- rvk · 2022-04-22 13:32 That seems to be a problem in the server. Why would you pass content- type if there is no content to send. https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.5 QuoteA sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type. Why are you using POST if there is no data to send? Won't a GET do the same? ---------------------------------------------------------------------- BlueIcaro · 2022-04-22 14:07 Quote from: rvk on April 22, 2022, 03:32:42 pmThat seems to be a problem in the server. Why would you pass content-type if there is no content to send. https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.5 QuoteA sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type. Why are you using POST if there is no data to send? Won't a GET do the same? Hi, that's we I asked if this is a bug of Sypnase library. Acording to documentation of the server, which is a ABB Indutrial Robot Controler [https://developercenter.robotstudio.com/api/rwsApi/index.html QuoteRobot Web Service currently use following content types:     application/xhtml+xml For XML representation     application/json For JSON representation     application/x-www-form-urlencoded For "form data" And when you send a command like this https://developercenter.robotstu dio.com/api/rwsApi/elog_clearall_page.html where you can read: QuoteMethod: POST URL Params: action=clearall Required Data Params: None (...) curl --digest -u "Default User":robotics -X POST "http://localhost/rw/elog?action=clearall"The server needs 'Content- Type: ' with value  application/x-www-form-urlencoded even you send any data, and all info is the url. May be a wrong implementation on Server?. It's strange because ABB is a swedish company, and the use to do the all thing according the manual, rules, laws, etc. /BlueIcaro ---------------------------------------------------------------------- rvk · 2022-04-22 14:17 And with other server implementations (like Medix) if you set the content-type to application/x-www-form-urlencoded and you DON'T provide any data/content, it will throw an error. Quote from: BlueIcaro on April 22, 2022, 04:07:07 pmcurl --digest -u "Default User":robotics -X POST "http://localhost/rw/elog?action=clearall" The server needs 'Content-Type: ' with value  application/x-www-form- urlencoded even you send any data, and all info is the url. May be a wrong implementation on Server?. It's strange because ABB is a swedish company, and the use to do the all thing according the manual, rules, laws, etc. Did you test that curl statement? Try it with an extra -v parameter. curl -v --digest -u "Default User":robotics -X POST "http://localhost/rw/elog?action=clearall" Do you see any Content-Type being passed by curl ??? (I don't) Code: [Select]* Server auth using Digest with user 'Default User' > POST /rw/elog?action=clearall HTTP/1.1 > Host: localhost > User-Agent: curl/7.74.0 > Accept: */* > So, does that throw an error for you? ---------------------------------------------------------------------- BlueIcaro · 2022-04-22 14:22 Hi, I used curl (never used  before), and here is the output: QuoteC:\Users\jorge>curl -v --digest -u "Default User":robotics -X POST "http://localhost/rw/elog?action=clearall" *   Trying 127.0.0.1:80... * Connected to localhost (127.0.0.1) port 80 (#0) * Server auth using Digest with user 'Default User' > POST /rw/elog?action=clearall HTTP/1.1 > Host: localhost > User-Agent: curl/7.79.1 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 401 Unauthorized < Vary: Accept-Encoding < X-Frame-Options: SAMEORIGIN < Content-Type: text/plain < X-Content-Type-Options: nosniff < Date: Fri, 22 Apr 2022 14:20:16 GMT < Cache-Control: no-cache < Content-Length: 29 < X-XSS-Protection: 1; mode=block < Connection: Keep-Alive < WWW-Authenticate: Digest realm="validusers@robapi.abb", domain="/", qop="auth", nonce="M2ViN2MxY2I0MDg5YWIwNzp2YWxpZHVzZXJzQHJvYmFwaS5hYmI 6MTgwNTFhNTFhMmE6MQ==", opaque="799d5", algorithm="MD5", stale="FALSE" < Accept-Ranges: bytes < * Ignoring the response-body * Connection #0 to host localhost left intact * Issue another request to this URL: 'http://localhost/rw/elog?action=clearall' * Found bundle for host localhost: 0x1a051d18da0 [serially] * Re-using existing connection! (#0) with host localhost * Connected to localhost (127.0.0.1) port 80 (#0) * Server auth using Digest with user 'Default User' > POST /rw/elog?action=clearall HTTP/1.1 > Host: localhost > Authorization: Digest username="Default User",realm="validusers@roba pi.abb",nonce="M2ViN2MxY2I0MDg5YWIwNzp2YWxpZHVzZXJzQHJvYmFwaS5hYmI6MTg wNTFhNTFhMmE6MQ==",uri="/rw/elog?action=clearall",cnonce="921882676e0b 845dc36edabdd01bf4ee",nc=00000001,algorithm=MD5,response="e86208c737f4 f8d8c17f89eb178c2e46",qop="auth",opaque="799d5" > User-Agent: curl/7.79.1 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 415 Unsupported Media Type < Set-Cookie: -http- session-=2::http.session::838cdb68c4aa8a5dadd9afd880f23dfb; path=/; httponly < Set-Cookie: ABBCX=13; path=/; httponly < Vary: Accept-Encoding < X-Frame-Options: SAMEORIGIN < Content-Type: application/xhtml+xml < X-Content-Type-Options: nosniff < Date: Fri, 22 Apr 2022 14:20:16 GMT < Cache-Control: no-cache="set-cookie", max-age=0, no-cache, no-store < Content-Length: 417 < X-XSS-Protection: 1; mode=block < Connection: Keep-Alive < Pragma: no-cache < Expires: -1 < Accept-Ranges: bytes < rw
-1073414146d:\workspaces\robotso ftware\kernel\6.08.xx\areas\robapi2\components\rws_elogsrv\rws_resourc e_elog.cpp[409] content type is not supported code:-1073414146 icode:415
* Connection #0 to host localhost left intact /BlueIcaro Edit: Using the example of documentation. So there is same thing weird. So I going to report to ABB. ---------------------------------------------------------------------- rvk · 2022-04-22 14:33 Quote from: BlueIcaro on April 22, 2022, 04:22:47 pmEdit: Using the example of documentation. So there is same thing weird. So I going to report to ABB. Yeah... if their own example also give that same error... ---------------------------------------------------------------------- BlueIcaro · 2022-04-22 14:42 Thanks for all rvk. I was fighting with this two days. I read the examples using curl and I never test them  Curl command gives me more info. Why I never used  I wrote a post in ABB oficial forum (https://forums.robotstudio.com/discussion/13427/rws-clear-all-log- sample-from-documentation-fails#latest), If I have news I'll write report here. May be can help some one more in future. Now I sure that is not a bug from Synapse package. /BlueIcaro