By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,771 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,771 IT Pros & Developers. It's quick & easy.

How do NetworkCredential and WebClient work?

P: n/a
I read many examples with NetworkCredential and WebClient, but no one
with a real http address.
They all work in theory, but I wasn't able to use them in the real
world.
The following code should access an ebay page. There is no
redirection involved in TestPage. If you have an ebay account you can
try it in 1 minute.

What's wrong with my code?

Dim UserName As String = "stenci"
Dim Password As String = "vivalafica"
Dim TestPage As String = _
"http://my.ebay.com/ws/eBayISAPI.dll?MyeBay&MyeBay=" _
& UserName
Dim Cli As New Net.WebClient

Dim Txt1 = Cli.DownloadString(TestPage)
IO.File.WriteAllText("C:\1.txt", Txt1)

Cli.Credentials = New Net.NetworkCredential(UserName, _
Password)

Dim Txt2 = Cli.DownloadString(TestPage)
IO.File.WriteAllText("C:\2.txt", Txt2)

MsgBox("Before setting credentials is not logged=" & _
InStr(Txt1, "Sign In: My eBay") & " is logged=" _
& InStr(Txt2, "Sign In: My eBay"))

MsgBox("After setting credentials is not logged=" & _
InStr(Txt1, "My Summary") & " is logged=" _
& InStr(Txt2, "My Summary"))

Thanks,
Stefano

Feb 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Tosco" <st***********@gmail.comschrieb:
>I read many examples with NetworkCredential and WebClient, but no one
with a real http address.
eBay uses a different authentication approach similar to those used by
Google:

<URL:http://dotnet.mvps.org/dotnet/code/net/#CookieRequest>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 4 '07 #2

P: n/a
eBay uses a different authentication approach similar to those used by
Google:

<URL:http://dotnet.mvps.org/dotnet/code/net/#CookieRequest>
Thank you Herfried, but I don't understand the german part, I can only
look at the code examples, and it doesn't help.
I think the part that I need in that page is this:

Dim Client As New WebClient()
Client.Headers.Add("Content-Type", "application/x-www-form-
urlencoded")
Client.UploadData( _
"https://www.google.com/adsense/login.do", _
"POST", _
Encoding.UTF8.GetBytes("username=<user name>&password=<password>")
_
)
Client.Headers.Clear()
Client.Headers.Add("Cookie", Client.ResponseHeaders("Set-Cookie"))
Dim Data() As Byte = _
Client.DownloadData("https://www.google.com/adsense/report/
overview")
Client.Dispose()
MsgBox(Encoding.UTF8.GetString(Data))

I tried to use it for ebay (I actually need it in 2 different domains,
but I hope than after succeding with ebay once I will be able to use
it with the other urls) and it didn't work.
This is what I did:

Dim UserName As String = "username"
Dim Password As String = "password"
Dim Client As New Net.WebClient()
Client.Headers.Add("Content-Type", "application/x-www-form-
urlencoded")
Client.UploadData( _
"https://signin.ebay.com/ws/eBayISAPI.dll", _
"POST", _
System.Text.Encoding.UTF8.GetBytes( _
"MfcISAPICommand=SignInWelcome&siteid=0&co_partner Id=2&" & _
"UsingSSL=1&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&userid="
_
& UserName & "&pass=" & Password))
Client.Headers.Clear()
Client.Headers.Add("Cookie", Client.ResponseHeaders("Set-Cookie"))
Dim Data() As Byte = _
Client.DownloadData("http://my.ebay.com/ws/eBayISAPI.dll?
MyeBay")
Client.Dispose()
MsgBox(System.Text.Encoding.UTF8.GetString(Data))

Stefano

Feb 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.