Proxy Server with wxURL Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Proxy Server with wxURL

Post by Tyler »

In my application I use wxURL to access the internet and retrieve information from a web page. The problem is, it doesn't work from behind my user's proxy server. How would I go about getting around this? Is it as simple as changing my url from www.wxforum.org to www.wxforum.org:proxyPort ?

Thanks for the help.
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

url.SetProxyServer("proxy.isp.com:8080");
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler »

wxURL::SetDefaultProxy or wxURL::SetProxy?
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

both works
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler »

Thanks!
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

tho im pretty sure your know the difference... SetDefaultPRoxy works globally, SetProxy workson a per-instance basis... just so you know.

For those people wanting to use HTTP low-level, to use a proxy you connect to the proxy instead of the server, and use this:

GET http://server.com/path/to/file.php HTTP/1.1
HOST: server.com
Connection: Close

That is, if my research tells me right...
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler »

Hmm, even though I think my code is right, something is still awry. Here's what I'm using:

Code: Select all

wxInputStream *data;
// wxURL::SetDefaultProxy(proxyStr);
wxURL url2(goTo); // goto is the full url to a php script
url2.SetProxy(proxyStr); //proxy string is in the format proxyServer:port
data = url2.GetInputStream();

if (!data)
		ErrorMessage("Connection to proxy failed.");
else {
		ErrorMessage("Connection successfull.")
}
I've been playing with both SetDefaultProxy and SetProxy. When I use SetProxy, data == NULL and the if check fails. When I use SetDefaultProxy data is != NULL but on attempting to read from it the program crashes so I can only assume that it's garbage data. I'm confident that my proxy is working because my browser can tunnel through it to get on the internet (I'm using squid on Fedora Core).

Do you have an actual working example that you've used to connect to a proxy that I can look at, or can you see where I'm going wrong?

Thanks for your help.
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

care telling me the exact address of the script, and the proxy server address? wx is very particular about formatting
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler »

Sure,

goto = {"http://www.mycustomcd.com/index.php"}

and proxyStr = {"192.168.1.101:80"}

My ip is 192.168.1.102.


-Tyler
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler »

It was a blasted bug in wx. I believe I've got it.

in src\common\url.cpp I altered the code to be the following:

Code: Select all

 // When we use a proxy, we have to pass the whole URL to it.
  wxInputStream *the_i_stream;
  
  if (!m_useProxy)
  {
      the_i_stream = m_protocol->GetInputStream(m_url);
  }
  else
  {
      wxString fullPath = /*Begin Fix*/m_url +/*End Fix*/ m_path;

      if (HasQuery())
          fullPath += wxT("?") + m_query;
      
      if (HasFragment())
          fullPath += wxT("#") + m_fragment;
      
      the_i_stream = m_protocol->GetInputStream(fullPath);
  }

  if (!the_i_stream)
The fix is above. That gives me a valid stream object, but looks like I'm going to have to make similar fixes elsewhere because the data coming back doesn't look kosher. :(
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

try getting the 2.6.2 CVS, sorry i forgot - 2.6.1 had very faulty wxURL implementations...
Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

CVS

Post by Lamego »

Could someone confirm that this has been fixed on the CVS ?
I am using 2.6.2, after setting up the proxy the GetInputStream() simply blocks for some time and I don't get a successfull result.

Thanks
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Re: CVS

Post by Ryan Norton »

Lamego wrote:Could someone confirm that this has been fixed on the CVS ?
I am using 2.6.2, after setting up the proxy the GetInputStream() simply blocks for some time and I don't get a successfull result.

Thanks
Are you sure the proxy server works? If you give me a few slices of code I can test here if you'd like.
[Mostly retired moderator, still check in to clean up some stuff]
Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

test code

Post by Lamego »

I am sure the proxy works, I am using for my daily browsing, also I am using with a wxSocket connection (estbalishing an HTTP tunnel).

The proxy is from an company intranet so you wouldn't be able to use it:

Code: Select all

  // Try to fech online logo
  wxURL url(_("http://www.pt-link.net/services/logo.png"));
  url.SetProxy(_("proxy.mycompany.com:8080"));
  wxInputStream *data = url.GetInputStream();
  if(data)
  {
    wxFile fTest(_("logo.png"), wxFile::write );
    wxFileOutputStream streamout( fTest );
    data->Read(streamout);
    fTest.Close();
  }
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net
Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

strange

Post by Lamego »

It did work with a squid proxy setup on localhost, I need to do some investigation. It would be some problem specicif to the proxy version I am using.
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net
Post Reply