How do NetworkCredential and WebClient work?

T

Tosco

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
 
T

Tosco

eBay uses a different authentication approach similar to those used by

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_partnerId=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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top