The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Doing an Http Post

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Doing an Http Post Posted: Aug 14, 2004 4:26 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Doing an Http Post
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

Awhile back, I made a post about HTTP Queries from VisualWorks. Let's have a look at how an HTTP Post would look. You are going to end up working with the same HttpClient (or HttpsClient) class as before - and you are going to need to craft a custom Request object. Let's presume that the post is like a post from a form - here's what we need to do:



	|  client request |
	client := HttpClient new.
	request := HttpRequest post: 'http://www.mysite.com/someForm'.
	request contentType: 'application/x-www-form-urlencoded'..
	request contents: 'arg1=true&arg2=Fred&arg3=Barney'.
	response := [client executeRequest: request]
		on: self httpExceptions
		do: [:ex | nil].
	response ifNil: [response := client originalResponse].
	^response

Now, you wouldn't want to hard code the encoding, or the data (or the URL). In the Http-Access and NetResources packages (in the Public Store), there's a simple API for doing posts with that data passed in. Encoding the data is a fairly simple thing; you need something like this:

| arg1 arg2 arg3 stream | stream := WriteStream on: String new. stream nextPutAll: 'arg1=', (URI encode: arg1). stream nextPutAll: '&arg2=', (URI encode: arg2). stream nextPutAll: '&arg3=', (URI encode: arg3). ^stream contents.

That will give you back a string suitable for passing as an url encoded string in a POST form. That's pretty much it though. By mucking around with the encoding and the data being passed, you can create any kind of POST request pretty easily. Next time I'll take a look at the way such a post might be handled by a VisualWorks Web Toolkit servlet.

Read: Doing an Http Post

Topic: A simple way to access JavaDoc attributes at runtime Previous Topic   Next Topic Topic: Convention gaming

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use