473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How do NetworkCredential and WebClient work?

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
2 3928
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
7
by: Crirus | last post by:
Hi all! I use a webClient for requesting data from a server of mine. Should I worry about long ammount of data sent by server in the client side? Or, another way, should I send some kind of a...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
6
by: Giovanni | last post by:
Hi Guys, Really strange problem I am experiencing... I have setup a virtual directory with Read Only permissions on an ISA/IIS server (SBS 2003). In that virt. dir., I placed 1 file...
1
by: vin.dor | last post by:
Dear All, I am using WebClient in my Visual Studio .Net 2003 project to download an image from the Internet. The following is my function: C# Code: public static bool downloadFile(string...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
2
by: Tosco | last post by:
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...
1
by: Guy | last post by:
I use SmtpClient to send mail. My customer reported that sending mail was throwing an exception on his machine "the SMPT client requires a secure connection or the client was not authenticated". ...
2
by: MichaelSchoeler | last post by:
Hi, I'm having problems with the WebClient class regarding UTF-8 encoded data. When I access a specific webservice directly I can see the data arrives in corretly formatted UTF-8. But when I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.