Trouble with http post

I am trying to create an http post request that sends a series of
parameters and then 512 bytes of hex data in the body.

I think the post needs to be formatted something like this:
http://url/set.cgi?dst=RES&type=11&id=1&512 bytes here

I can get the parameters set properly and make the call to the server:

params = {‘dst’ => ‘RES’, ‘id’ => ‘1’, ‘type’ => “11”}
uri = URI(‘http://url:8081/set.cgi’)
res = Net::HTTP.post_form(uri, params)

But I can’t seem to add on the hex values.

Does anyone have some suggestions? It seems like I may need to go lower
level than the ruby post. It seems to want to map all the parameters so
I can’t pass it a basic string.

Here’s some code that works in objective-C. I’m not that familiar with
objective-C but it looks to me like the body contains the parameters and
the hex data and the ruby map function is throwing me off.

  • (void)sendURL:(NSURL *)url postData:(NSData *)postData
    replyType:(NSInteger)replyType target:(id)target userInfo:(id)userInfo
    {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
    cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
    timeoutInterval:REQUEST_TIMEOUT_INTERVAL];

    if (postData) {
    [request setHTTPMethod:@“POST”];
    [request setHTTPBody:postData];
    }

On Sat, Nov 10, 2012 at 11:25 PM, Shaun A. [email protected] wrote:

I am trying to create an http post request that sends a series of
parameters and then 512 bytes of hex data in the body.

I think the post needs to be formatted something like this:
http://url/set.cgi?dst=RES&type=11&id=1&512 bytes here

Those two statements are at odds; adding a parameter to the query
string is not putting “data in the body”.

Have you read the doc for Net::HTTP? There’s example code for
exactly what you’re trying to do…

Hi Hassan,

Thanks for the reply. I have read and re-read the NET::HTTP docs and it
doesn’t do what I want because it was showing all the parameters as
hashes. I was trying to send three values as a hash and one as a string
and I couldn’t mash them together. I ended up figuring it out and I need
to create the url myself rather than using any of the ‘easy’ methods.

This is what ended up working:

data = “dst=#{dst}&type=#{type}&id=#{id}&#{data_array.join}”
resp, data = http.post(path, data)
p resp.body

On Sun, Nov 11, 2012 at 12:09 PM, Shaun A. [email protected] wrote:

data = “dst=#{dst}&type=#{type}&id=#{id}&#{data_array.join}”
resp, data = http.post(path, data)
p resp.body

Hi, Shaun,

I’m looking here:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-post
and it shows that data must be a string. What documentation are you
looking at?

Hi Tamouse,

I was looking at the examples higher up on the page. The POST and POST
with Multiple Values show the form values as hashes. I didn’t make it to
that part of the documentation. I guess I didn’t read it that well after
all!

Thanks for the link. I think I have a working solution now.

Shaun

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs