473,395 Members | 1,443 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,395 software developers and data experts.

Connect through proxy?

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 4924
Bump. Anybody? Sorry this is a kind of bizarre problem.
Jul 28 '08 #2
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
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.net/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
Bump again, sorry guys.
Jul 29 '08 #5
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
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
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...
22
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...
4
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,...
1
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...
3
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...
0
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...
0
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....
1
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
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
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...

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.