473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connect through proxy?

51 New Member
Ok this question may seem odd, but I'll do my best to explain it.
I'm writing a script for development purposes so this doesn't need to run in a browser, actually this would be a lot easier if it could, but it can't. I'm running it with:

# /usr/local/bin/php script.php

The script in question uses the Flickr API so it needs to connect to the internet. And here in lies the question. The way I'm connecting to the internet is through an ssh proxy. I run the command.

# ssh -D 1080 mchang@192.168. 107.30

Is there a way to tell the script to connect through that proxy?
Jul 25 '08 #1
6 4937
Muffinthief
51 New Member
Bump. Anybody? Sorry this is a kind of bizarre problem.
Jul 28 '08 #2
pcfreak30
5 New Member
luckly, the other day i was looking up the fopen function in the php manual. someone posted a comment with a proxy class. It allows to to fetch pages even if ur behind a proxy. The header commands are quite simple in my opinion. They are identical to talking to a web server.

http://www.php.net/fopen

just scroll down trough the comments, and u will find it

:-D
Jul 28 '08 #3
Muffinthief
51 New Member
Ok guys thanks for the help. after a little more research I've tracked down my problem. The Flickr API (or at least what I'm using) uses PEAR. and you need to specify a proxy when making an HTTP request. Following the example from: http://www.collicott.n et/jess/examples/php/pear/http_request/

I end up with:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once 'HTTP/Request.php';
  3.  
  4. $params['proxy_host'] = '127.0.0.1'; //proxy is running on local host
  5. $params['proxy_port'] = 1080; //running on port 1080
  6. $webAddress = 'http://www.collicott.net/nickolas/';
  7.  
  8. $req =& new HTTP_Request($webAddress, $params);
  9. if (!PEAR::isError($req->sendRequest())) {
  10.     $webContent = $req->getResponseBody();
  11.     $webContent = preg_replace('/<!.*>|<\/?(html|head|meta|body).*>|<title>.*<\/title>/i','',$webContent); // strip tags
  12.     $webContent = preg_replace('/src="/i','src="'.$webAddress,$webContent); // fix images
  13.     $webContent = preg_replace('/href="/i','href="'.$webAddress,$webContent); // fix links
  14.     echo $webContent;
  15. }
  16. ?>
This doesn't work, it runs as if I have no internet connection. My first post shows how I set up the proxy. Does anybody have any suggestions?
Jul 28 '08 #4
Muffinthief
51 New Member
Bump again, sorry guys.
Jul 29 '08 #5
Muffinthief
51 New Member
Ok guys well here's a simplified example of what I'm trying to do.

I start the proxy using "ssh -D 1080 mchang@192.168. 107.30"

this starts a proxy to another part of the machine (I'm using Solaris 10) on part 1080.

Then I have the php code.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once './HTTP/Request.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_PRINT);
  5.  
  6. $webAddress = 'http://www.yahoo.com';
  7.  
  8. $req =& new HTTP_Request($webAddress);
  9. $req->setProxy('127.0.0.1', 1080);
  10. if (PEAR::isError($req->sendRequest())) {
  11.     echo "ERROR!\n";
  12. }
  13. $req->sendRequest();
  14. $webContent = $req->getResponseBody();
  15. echo $webContent;
  16. ?>
Which should get yahoo.com and be all happy, but I get a "Malformed response" error. So I think either PEAR doesn't support Socks proxies or I'm doing something wrong. Does anybody have any ideas?
Jul 30 '08 #6
Muffinthief
51 New Member
Sorry, but I'm going to have to bump this one more time...
Aug 2 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2928
by: Manjesh Gowda | last post by:
Hi all, I am maintaing a persistent HTTP connection using the "HTTP CONNECT" method , this works fine for many proxies like Squid, ISA , etc. But the iPlanet proxy disconnects the conneciton after 15 mins. It fires the HTTP 501 status code saying " Server Internal Error". Is there any way the i can overcome this problem and maintain a persistent HTTP connection or should i reconnect the socket for certain time interval.
22
3255
by: Kristof Thys | last post by:
Hello, I'm developing a C# - windows forms application. To get some information for my application, I'm connecting to an URL, wich gives me XML generated using php. With 90% of the users, this code just works fine: WebRequest request = WebRequest.Create(URL);
4
4462
by: WATYF1 | last post by:
Hello. I'm writing a VB.NET app to check email message counts for both POP3 and IMAP4. I'm using TCPClient to connect, and a NetworkStream to send simple commands. It's a very simple bit of code, actually... the problem is, if the user is behind a proxy, then the Connect method fails (times out). How do I get around this? I thought this would be a common issue and that there would be plenty of code out there to demonstrate how to...
1
5782
by: Gaurav | last post by:
I am trying to add a webreference to a Web Service. I m connected to internet through Proxy server. I am getting following error. Anybody can help??/ Please. There was an error downloading 'http://www.webservicex.net/sendsmsworld.asmx?WSDL'. The underlying connection was closed: Unable to connect to the remote server.
3
9537
by: nandan | last post by:
Yes. My client has a proxy server. That much i know. In my application I make two kinds of calls that are affected by the proxy server I finally got the webservice call working. But my httpwebrequest.GetReponse() function call throws the above error. So here's what i do in the case it works.. //THIS WORKS
0
1994
by: =?Utf-8?B?TWlrZTEz?= | last post by:
Sorry for the cross post from dontnet.framework but I'm hoping this may see more activity here. I have written an application to access a web service. The application runs at multiple sites and must cross a proxy server. The application runs fine through all proxy servers but one that is configured to require a "User-Agent" header. I have added the user agent string, however it does not seem to be passed during the HTTP CONNECT to...
0
2377
by: =?Utf-8?B?TWlrZTEz?= | last post by:
Sorry for the cross post; I'm hoping this will get a response here... I have written an application to access a web service. The application runs at multiple sites and must cross a proxy server. The application runs fine through all proxy servers but one that is configured to require a "User-Agent" header. I have added the user agent string, however it does not seem to be passed during the HTTP CONNECT to utilize the proxy server. ...
1
1322
by: Edwin.Madari | last post by:
jlist wrote: switching to urllib2, installing the proxy opener, worked for me. here is the sample. variable names are self explanatory import urllib2 proxy=urllib2.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy}) opener=urllib2.build_opener(proxy, urllib2.HTTPHandler) urllib2.install_opener(opener) req = urllib2.Request(url, form, headers)
6
13680
by: Patrick.Simons | last post by:
I try to connect a FTPWebRequest through Proxy and VPN to a remote FTP- server. Sometimes it works sometimes not. When my VB.Net-App (2005) returns the error on the GetResponse-Method, I'll try to use the Windows Explorer to go on the FTP-URI and this always works. So the problem should come from my app. my simplified code: Private m_oFTP As FtpWebRequest Private oResponseDir As FtpWebResponse = Nothing
0
8385
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.