RestSharp, PowerShell and Parameters

954 views
Skip to first unread message

Matt Thompson

unread,
Apr 18, 2011, 4:00:56 AM4/18/11
to RestSharp
Hi Guys,

I'm trying to use RestSharp from PowerShell and I'm struggling when it
comes to POSTing data.

I've this script here, which uses the GET method and works ok (I've
replaced the Tumblr account details with xxxxx):

#######################################
# Attempt one point five with RestSharp - authentication test
#######################################
add-type -Path RestSharp.dll

$client = "http://xxxxxxxx.tumblr.com"
$request = "api/authenticate"

#$r = New-Object RestSharp.RestRequest($request, "POST")
$r = New-Object RestSharp.RestRequest($request) # this
authenticates...
$c = New-Object RestSharp.RestClient($client)

[Void] $r.AddParameter("email", "xxxxxxx")
[Void] $r.AddParameter("password", "xxxxxx")

$rr = $c.Execute($r)
$rr


If i switch from a GET to a POST (I need to for writing to the Tumblr
API) I get an authentication error. I wonder if it is related to the
encoding of data...?

these are the lines to swap over to switch from a GET to a POST:

$r = New-Object RestSharp.RestRequest($request, "POST")
#$r = New-Object RestSharp.RestRequest($request) # this auth


Has anybody similar experience with PowerShell or C#?

Thanks for any feedback,
Matt

David Poulin

unread,
Apr 18, 2011, 4:20:45 AM4/18/11
to rest...@googlegroups.com
Hi!

I never used PowerShell, but, did you try to use expected enum argument ?

$r = New-Object RestSharp.RestRequest($request, RestSharp.Method.GET) ?

David


2011/4/18 Matt Thompson <thomp...@gmail.com>

John Sheehan

unread,
Apr 21, 2011, 4:05:41 PM4/21/11
to rest...@googlegroups.com
Yeah, try David's suggestion and let us know if that works.

John

Matt Thompson

unread,
May 18, 2011, 4:26:29 PM5/18/11
to RestSharp
Thanks for the reply, I've just tried this:

$r = New-Object RestSharp.RestRequest($request,
[RestSharp.Method]::POST)

but had no joy with it...
the content is "Post cannot be empty." and the ResponseUri is this
"http://www.tumblr.com/api/write?
email=XXXXXX&password=XXXXXX&Title=test test&Body=testing with
RESTSharp&IsPrivate=True&group=XXXXXXXXXX" which implies to me it's
still doing a GET.

Any help appreciated... :)


On Apr 18, 9:20 am, David Poulin <dpou...@gmail.com> wrote:
> Hi!
>
> I never used PowerShell, but, did you try to use expected enum argument ?
>
> $r = New-Object RestSharp.RestRequest($request, RestSharp.Method.GET) ?
>
> David
>
> 2011/4/18 Matt Thompson <thompson...@gmail.com>
Reply all
Reply to author
Forward
0 new messages