• c++ SFML Http help
    14 replies, posted
When I try to send a HTTP Post request which has characters 'ä' or 'ö' in the body it doesn't seem to get sent. Is there some way to get it work?
Are you URL-encoding your data?
I don't think you can have those characters in a URL?
[QUOTE=elevate;42813297]I don't think you can have those characters in a URL?[/QUOTE] I don't have them in a url. They are in the Http request body. [QUOTE=Dienes;42813263]Are you URL-encoding your data?[/QUOTE] I dont know what that is
[QUOTE=TNOMCat;42813330]I don't have them in a url. They are in the Http request body.[/QUOTE] I'm pretty sure it's the same deal for the "body" as well. You're probably gonna need to encode the body.
[QUOTE=elevate;42813360]I'm pretty sure it's the same deal for the "body" as well. You're probably gonna need to encode the body.[/QUOTE] How do I encode it? When I submit data containing those letters through a form on a website and capture the post request they are shown as normal äääööö in the body.
[url=http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm]This might help.[/url] Or better yet, you're a programmer. Why don't you make your own encoder? You'll learn a little something, which is what good programmers should be doing. Take note that the link above only accepts a string, which only uses ANSI characters. What if you wanted something more? I'd use u32string.
[QUOTE=TNOMCat;42813411]How do I encode it? When I submit data containing those letters through a form on a website and capture the post request they are shown as normal äääööö in the body.[/QUOTE] Most likely because the encoding/decoding is transparent to the user. I don't know if SFML has a built-in method of doing this conversion, but basically you take the UTF-8 representation of the character and write each byte in hexadecimal preceded by a '%'. E.g. 'ö' would become '%C3%B6'.
[QUOTE=elevate;42813297]I don't think you can have those characters in a URL?[/QUOTE] You can. And have been able to for quite a while now. [url]http://blåband.se/[/url] Is a valid address. Some registrars might not allow it, but it's perfectly valid.
What is your content type? You only need to URI encode the body if it's application/x-www-form-urlencoded. Have you checked to make sure that the request is not being sent. You can use tools like Fiddler or Wireshark to sniff your traffic and see if the request is being sent or not. You can also see the response. It might also help to know what you're trying to send and where you're trying to send it.
[QUOTE=Boris-B;42845677]What is your content type? You only need to URI encode the body if it's application/x-www-form-urlencoded. Have you checked to make sure that the request is not being sent. You can use tools like Fiddler or Wireshark to sniff your traffic and see if the request is being sent or not. You can also see the response. It might also help to know what you're trying to send and where you're trying to send it.[/QUOTE] content type is "multipart/form-data" at all times even when I have the ä or ö characters in the body Fiddler only works for web browsers, and I never got wireshark to work. So no idea if it actually gets sent and I'm trying to post comments to a website.
I've been reading up on multipart/form-data and here's what I figured out. multipart/form-data allows you to send information in multiple parts. Each part can have its own content type. You can read up on the details here: [url]http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2[/url] I have found some interesting bits here: [quote] a name attribute specifying the control name of the corresponding control. [b]Control names originally encoded in non-ASCII character sets may be encoded using the method outlined in [RFC2045].[/b] [/quote] and a bit lower [quote] Each part may be encoded and the "Content-Transfer-Encoding" header supplied if the value of that part does not conform to the default (7BIT) encoding (see [RFC2045], section 6) [/quote] Looks like the default encoding is US-ASCII. Another encoding can be supplied. For your needs you'll probably want what's mentioned in the first quote. Looking at RFC2045 ([url]http://www.ietf.org/rfc/rfc2045.txt[/url]) I can find the following (5.1) You'll need to specify the encoding (utf-8) with the content type of the part being sent out. It'll probably look like this. [code]Content-Type: text/plain; charset="utf-8"[/code] This of course, needs to be set for the part of the form that contains the utf-8 characters. You could also specify it on all the parts (unless you're dealing with non text or something of the like) as utf-8 as it's retro compatible with ASCII. I have no idea how you're going to do this with SFML tho. Googling something about SFML, HTTP and utf-8 will probably send you on the right way. As for Fiddler. From what I read on their site, it doesn't only work with browsers. It works with anything that supports a proxy. Most libraries/applications are smart enough to detect windows' proxy settings and automatically apply them.
[QUOTE=Boris-B;42867724] You'll need to specify the encoding (utf-8) with the content type of the part being sent out. It'll probably look like this. [code]Content-Type: text/plain; charset="utf-8"[/code] This of course, needs to be set for the part of the form that contains the utf-8 characters. You could also specify it on all the parts (unless you're dealing with non text or something of the like) as utf-8 as it's retro compatible with ASCII. I have no idea how you're going to do this with SFML tho. Googling something about SFML, HTTP and utf-8 will probably send you on the right way. [/QUOTE] When I send the request through the web browser normally, the captured request's multipart body doesn't contain any references to any encoding/charset anywhere. But it should right? Or does fiddler's captured raw http request data exclude that? What I'm sending through my program is an exact copy of one of the captured http post requests (except message taken from user input). And Fiddler doesn't capture anything from my program by default. I think I'll have to edit some config somewhere but I'll read about that later.
I'm pretty sure that fiddler show everything. I guess that utf-8 is technically not required. If it's omitted the server would probably interpret it as ascii. It all kinda works because utf-8 works in ascii. I don't know how HTTP requests work in SFML. I'm afraid I can't help you with that bit. When you send the data on the web form, do you put in the non ascii characters?
Maybe SFML is automatically adding some header field for encoding.... It does automatically generate some necessary things if they are missing, for convenience. Even though its not an necessary field I cant come up with other explanations
Sorry, you need to Log In to post a reply to this thread.