Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Posting HTTP Form Data with Erlang
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rick Moynihan  
View profile  
 More options Aug 17 2010, 11:43 am
From: Rick Moynihan <r...@wgrids.com>
Date: Tue, 17 Aug 2010 16:43:51 +0100
Local: Tues, Aug 17 2010 11:43 am
Subject: [erlang-questions] Posting HTTP Form Data with Erlang
Does anyone know if there is an API that I can use to post HTTP form data?

I've looked at using inets:httpc, and it seems to have everything I
need, except that it doesn't appear to allow you to pass it a list of
key/value tuples and have them be encoded into the HTTP request as
application/x-www-form-urlencoded data.

Does anyone know if inets:httpc can do this, and if not whether there
are any libraries I can easily use?

Cheers,

R.

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscr...@erlang.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Raschke  
View profile  
 More options Aug 17 2010, 12:46 pm
From: Robert Raschke <rtrli...@googlemail.com>
Date: Tue, 17 Aug 2010 17:46:35 +0100
Local: Tues, Aug 17 2010 12:46 pm
Subject: Re: [erlang-questions] Posting HTTP Form Data with Erlang

On Tue, Aug 17, 2010 at 4:43 PM, Rick Moynihan <r...@wgrids.com> wrote:
> Does anyone know if there is an API that I can use to post HTTP form data?

> I've looked at using inets:httpc, and it seems to have everything I
> need, except that it doesn't appear to allow you to pass it a list of
> key/value tuples and have them be encoded into the HTTP request as
> application/x-www-form-urlencoded data.

> Does anyone know if inets:httpc can do this, and if not whether there
> are any libraries I can easily use?

Mochiweb provides a Request "object" to your callback function, and that has
a parse_post/0 function, which'll give you back a proplist of key/value
pairs from your POST body (and you can use parse_qs/0 for GET options after
the ? on the url).

Haven't used inets in a while.

Robby


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tino Breddin  
View profile  
 More options Aug 18 2010, 2:11 am
From: Tino Breddin <tino.bred...@googlemail.com>
Date: Wed, 18 Aug 2010 08:11:07 +0200
Local: Wed, Aug 18 2010 2:11 am
Subject: Re: [erlang-questions] Posting HTTP Form Data with Erlang
Something like the following might work for you as well:

httpc:request(post, {Url, [], "application/x-www-form-urlencoded, "key=value&key2=value2}, [], []).

If required you could use edoc:escape_uri(String) for the individual values.

Be sure to start inets before using httpc.

Tino

On Aug 17, 2010, at 6:46 PM, Robert Raschke wrote:

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscr...@erlang.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick Moynihan  
View profile  
 More options Aug 18 2010, 4:44 am
From: Rick Moynihan <r...@wgrids.com>
Date: Wed, 18 Aug 2010 09:44:40 +0100
Local: Wed, Aug 18 2010 4:44 am
Subject: Re: [erlang-questions] Posting HTTP Form Data with Erlang
On Wed, Aug 18, 2010 at 7:11 AM, Tino Breddin

<tino.bred...@googlemail.com> wrote:
> Something like the following might work for you as well:

> httpc:request(post, {Url, [], "application/x-www-form-urlencoded, "key=value&key2=value2}, [], []).

> If required you could use edoc:escape_uri(String) for the individual values.

Yes, I discovered that shortly after sending the email; prompting me
to write the following function, rather than take on an external
dependency, which I'm a little loathed to do for something so small:

url_encode(Data) ->
    url_encode(Data,"").

url_encode([],Acc) ->
    Acc;

url_encode([{Key,Value}|R],"") ->
    url_encode(R, edoc_lib:escape_uri(Key) ++ "=" ++
edoc_lib:escape_uri(Value));

url_encode([{Key,Value}|R],Acc) ->
    url_encode(R, Acc ++ "&" ++ edoc_lib:escape_uri(Key) ++ "=" ++
edoc_lib:escape_uri(Value)).

Thanks to everyone for your help,

R.

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscr...@erlang.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Fletcher  
View profile  
 More options Aug 18 2010, 8:06 am
From: Tim Fletcher <m...@tfletcher.com>
Date: Wed, 18 Aug 2010 05:06:42 -0700 (PDT)
Local: Wed, Aug 18 2010 8:06 am
Subject: [erlang-questions] Re: Posting HTTP Form Data with Erlang

> httpc:request(post, {Url, [], "application/x-www-form-urlencoded, "key=value&key2=value2}, [], []).

> If required you could use edoc:escape_uri(String) for the individual values.

URI escaping and application/x-www-form-urlencoded escaping are not
exactly the same thing though.

There's an implementation of both here:

  http://github.com/tim/erlang-percent-encoding

I'd appreciate any feedback on the correctness of the code/tests.

> Yes, I discovered that shortly after sending the email; prompting me
> to write the following function, rather than take on an external
> dependency, which I'm a little loathed to do for something so small:

Agreed. I usually copy/paste bits into other projects, for example:

  http://github.com/tim/erlang-webfinger/blob/master/src/webfinger.erl#...

Cheers,
Tim

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscr...@erlang.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »