View Full Version : How to make HTTP Post using Dream?
wuvist
09-13-2010, 04:20 AM
I think this is a stupid question, but I just can't figure it out.
I just want to make simple http post request like posting to:
http://mydomain.com/auth.ashx
with
username=XXX&password=YYY
I tried using:
Plug p;
Result<DreamMessage> res;
p = Plug.New(new XUri("http://mydomain.com/auth.ashx"));
Can't figure out how to pass username/password parameter to: p.Post method.
It accepts DreamMessage / XDoc parameter, but what I have is a simple NameValueCollection, dunno how to convert...
Thx~
The standard method is something like
p = Plug.New(new XUri("http://mydomain.com/auth.ashx")).With("username", "XXX").With("password", "YYY");
Each method on Plug returns a copy of the Plug with a new query parameter added.
wuvist
09-15-2010, 02:21 AM
Thx... but.... As what I understand, the With method attach the new query parameter to query string, not parameter in post....
public Plug With(string key, string value) {
return new Plug(Uri.With(key, value), Timeout, _headers, _preHandlers, _postHandlers, Credentials, _cookieJarOverride);
}
And that’s all there is to web requests using Plug. The class contains a number of extra methods for doing GET, PUT, POST, DELETE, etc., synchronous and asynchronous calling conventions, header and query arg manipulation, etc. Even doing a application/x-www-form-urlencoded POST is as simple as stringing together the name value pairs:
formPlug.With("key1",value1").With("key2","Value").PostQuery();
Since application/x-www-form-urlencoded is just a list of key/value pairs, similar to the Uri querystring, Plug provides PostQuery() as a method to convert the query args into a Post body and submit them. Of course, you can still use With() for query args and the regular Post() method with a manually specified POST body, if you need both query and post key/value pairs.
http://blog.developer.mindtouch.com/2009/05/18/consuming-rest-services-and-tdd-with-plug/
wuvist
09-15-2010, 10:40 AM
http://blog.developer.mindtouch.com/2009/05/18/consuming-rest-services-and-tdd-with-plug/
Thx Thx~
Althought PostQuery is thread-blocking, I think it is enough for me to dig out a workable solution.
:)
The suggestion in that article is that you can call .Post with a manually specified body. Arne or Steve will be able to give an authoritative answer!
Powered by vBulletin™ Version 4.1.3 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.