Curious about POST or PUT with a redirect...

33 views
Skip to first unread message

Tim Goeke

unread,
Apr 19, 2010, 11:52:00 PM4/19/10
to AS3 HttpClient
I am using HttpClient to talk to a RESTful Spring MVC application.
Everything seems to be working except when I PUT to a URI the update
goes through and the controller redirects to the GET for that URI.

It seems that HttpClient has already gone to the "Location:". Is
there a way to not redirect but rather intercept the server response
which has "Location:" header? I guess I'm a little surprised that the
header is being followed automatically and that I see different
behavior in other HTTP clients.

(For example using the REST client in IntelliJ shows the response
headers as expected.)

--
You received this message because you are subscribed to the Google Groups "AS3 HttpClient" group.
To post to this group, send email to as3-htt...@googlegroups.com.
To unsubscribe from this group, send email to as3-httpclien...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/as3-httpclient?hl=en.

gabe

unread,
Apr 20, 2010, 12:30:06 AM4/20/10
to AS3 HttpClient
As far as I can remember, I don't handle redirects automatically.

If possible you might try some manual debugging...

Tim Goeke

unread,
Apr 20, 2010, 1:30:26 PM4/20/10
to AS3 HttpClient
I added an "Accept: */*" header to the request and this seems to have
fixed it. For anyone wanting to PUT to a RESTful Spring MVC service,
this is what's working for me:

var uriString : String = "http://localhost:8080/ ***whatever your
path is***

var uri : URI = new URI( uriString )

var variables : Array = [
{name: 'field1', value: field1TI.text},
{name: 'field2', value : field2TI.text},
{name: '_method', value : 'PUT'}]

var request : HttpRequest = new Post( variables )
request.addHeader( "Accept", "*/*" )
request.addHeader( "Content-Type", "application/x-www-form-
urlencoded" )
request.addHeader( "Cache-Control", "no-cache" )

request.contentType = "application/x-www-form-urlencoded"

client.request( uri, request )

The critical parts are the form variable for the _method=PUT and the
Accept: */* header.

The duplicate Content-Type is probably not needed.
Reply all
Reply to author
Forward
0 new messages