Jump to content

Using winhttp to post

- - - - -

  • Please log in to reply
11 replies to this topic

#1
harshareddy75

harshareddy75

    Newbie

  • Members
  • PipPip
  • 20 posts
Hi,

I am using the winhttp library in C++ to post data to the server. Now I want to compress the data in gzip format before sending. I am not too sure sure of all the servers I am dealing with can handle compressed data. So I need some way to know if the server can handle it or not. I know that I can send a header "Accept Encoding" if I want to tell the server that I can handle compressed data, but I do not know how to ask the server if it can handle compressed data. I tried googling but there is hardly any information about sending compressed data to the server.

I know that strictly speaking this is not a c/c++ question and I apologize for that but I could not find a forum for problems like these.

Thanks
Harsha

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Content-Type: application/gzip
The server should complain if it doesn't like it. It'll probably be a 415 error message.
sudo rm -rf /

#3
harshareddy75

harshareddy75

    Newbie

  • Members
  • PipPip
  • 20 posts
Ok. But the reply from the server, when will it tell the client about the error message? Like posting will be done at WinHttpSendRequest, and the header would be sent earlier using winhttpaddheaderrequest. I am guessing I will have to do a qeuryheader to check for the status code but that can only be done after receiveresponse right ?? So if I get to know that the server does not support gzip then I will have to use winhttpsendrequest again to send the data in normal form? Please correct me if I am wrong.

and thanks for you reply

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
As far as I know, yes. I haven't done WinHTTP in almost a year, so I don't know the exact functions you need to call, but the basic idea behind what you said is right.
sudo rm -rf /

#5
harshareddy75

harshareddy75

    Newbie

  • Members
  • PipPip
  • 20 posts
ok. thanks again for your help.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
No problem! Let me know if you have more issues.
sudo rm -rf /

#7
harshareddy75

harshareddy75

    Newbie

  • Members
  • PipPip
  • 20 posts
hey,

I just realised that content-type: application/gzip actually does not work. I got a 500 status code. infact content-encoding: gzip worked.

Harsha

#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Oops...should be Content-Type: application/x-gzip. But if the Content-Encoding thing works, then that's fine. You should be careful, though, as they're not the same thing.

Content-Type: application/x-gzip means that whatever you're sending is a .gz archive, no matter what encoding (e.g. Base64, 7bit, etc.) you send it in.
Content-Encoding: gzip means that you're sending something that's gzipped, but the actual content could be something else like a webpage or an image file. Is this what you wanted?
sudo rm -rf /

#9
harshareddy75

harshareddy75

    Newbie

  • Members
  • PipPip
  • 20 posts
Yes content-encoding is what I actually wanted. I realised the difference sometime earlier but was still having some problems in running my program. anyhow finally it worked.

thanks again for your reply

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
No problem. If you want me to confuse you, just ask. :D
sudo rm -rf /

#11
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts

dargueta said:

No problem. If you want me to confuse you, just ask. :D
You should be flogged :P
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
dcs has already done that for me a few times. If you make a mistake, he will catch it.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users