473,800 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom HTTP request not returning expected results.

1 New Member
Please can somebody tell me why this isn't returning the index page? It is technically supposed to, and if somebody can get it to work I can then use remote download resume functionality in my site. According to <link removed>, it is a HTTP 1.1 request that supposedly should work...I can't find any syntax errors! What's wrong?

[php]<?php
ob_end_clean();
ob_implicit_flu sh(TRUE);

$host = "www.example.co m";
$url = "/index.html";
$port = 80;
$saveToFile = "index.html ";
$nn = "\r\n";
$method = "GET";

$fp = @fsockopen($pro xyHost ? $scheme.$proxyH ost : $scheme.$host, $proxyPort ? $proxyPort : $port, $errno, $errstr, 15);

if (!$fp)
{
html_error("Cou ldn't connect to ".($proxyHo st ? $proxyHost : $host)." at port ".($proxyPo rt ? $proxyPort : $port), 0);
}

if($errno || $errstr)
{
$lastError = $errstr;
print $errstr."<br>". $errno."<br>";
}

socket_set_time out($fp, 120);

if ($saveToFile)
{
if ($proxy)
{
echo "<p>Connect ed to proxy: <b>".$proxyHost ."</b> at port <b>".$proxyPort ."</b>...<br>\n";
echo "GET: <b>".$host.$url ."</b>...<br>\n";
}
else
{
echo "<p>Connect ed to: <b>".$host."</b> at port <b>".$port."</b>...<br>";
}
}

if ($saveToFile)
{
do {
$redirect = "";

$request =
"HEAD ".str_repla ce(" ", "%20", $url)." HTTP/1.1".$nn.
"Host: ".$host.$nn .
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MEGAUPLOAD 1.0; Alexa Toolbar)".$nn.
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5".$nn.
"Accept-Language: en-en,en;q=0.5".$n n.
"Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7 ".$nn.
"Pragma: no-cache".$nn.
"Cache-Control: no-cache".$nn.
"Keep-Alive: 300".$nn.
"Connection : Keep-Alive".$nn.$nn;

fwrite($fp, $request);

//$fs = fopen("debug.tx t", "wb");
//fwrite($fs, $request);

$head = "";

while(!feof($fp ))
{
$head.= fgets($fp, 128);
}

print "<br>HEAD: ".$head.$nn ;

if (stristr($head, "Location:" ))
{
$redirect = trim(cut_str($h ead, "Location:" , "\n"));
$rUrl = parse_url($redi rect);
$scheme = $rUrl["scheme"] == "https" ? "ssl://" : "";
$port = $rUrl["port"] ? $rUrl["port"] : ($scheme == "ssl://" ? 443 : 80);
$host = $rUrl["host"];
$url = $rUrl["path"].($rUrl["query"] ? "?".$rUrl["query"] : "");
}

if (stristr($head, "Content-Disposition:"))
{
$Content = trim(cut_str($h ead, "Content-Disposition:", "\n"))."\n" ;
if (stristr($Conte nt, "filename=" ))
{
$FileName = trim(trim(trim( cut_str($Conten t, "filename=" , "\n")), ";"), '"');
$saveToFile = dirname($saveTo File).PATH_SPLI TTER.basename($ FileName);
}
}
/*
if (@file_exists($ saveToFile))
{
if (is_numeric($fi lesize = @filesize($save ToFile)))
{
$Resume["use"] = TRUE;
$Resume["from"] = intval($filesiz e);
}
}
*/
} while (!empty($redire ct));
}



$request =
$method." ".str_repla ce(" ", "%20", $url)." HTTP/1.1".$nn.
"Host: ".$host.$nn .
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MEGAUPLOAD 1.0; Alexa Toolbar)".$nn.
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5".$nn.
"Accept-Language: en-en,en;q=0.5".$n n.
"Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7 ".$nn.
"Pragma: no-cache".$nn.
"Cache-Control: no-cache".$nn.
($Resume["use"] === TRUE ? "Range: bytes=".$Resume["from"]."-".$nn : "").
$http_auth.
$proxyauth.
$referer.
$cookies.
"Keep-Alive: 300".$nn.
"Connection : Keep-Alive".$nn.
$content_tl.$nn .$postdata;

//fwrite($fs, $request);
//fclose($fs);

fwrite($fp, $request);


while(!feof($fp ))
{
$data.= fgets($fp, 128);
}
print "<br>GET: ".$data.$nn ;

fclose($fp);


function cut_str($str, $left, $right)
{
$str = substr(stristr( $str, $left), strlen($left));
$leftLen = strlen(stristr( $str, $right));
$leftLen = $leftLen ? -($leftLen) : strlen($str);
$str = substr($str, 0, $leftLen);
return $str;
}
?>[/php]
Nov 1 '07 #1
1 1578
Atli
5,058 Recognized Expert Expert
Hi. Welcome to TSDN!

I've edited out some links in your post, as most links to sites outside TSDN are not allowed in the technical forums.

I've also moved your post into it's own thread in the PHP Forums. It is generally a very good rule to always post new questions in new threads, to avoid hijacking the old thread and to make it easier for other people facing similar problems to find your questions and any answers it may have received.

Check out the Posting Guidelines for more info on our posting policies.

Moderator
Nov 2 '07 #2

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

Similar topics

3
2423
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm writing a usercontrol which displays the typical two listboxes and the ability to move items from one to the other. The listboxes are populated with my custom objects (SwapItem), which simply
0
2300
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX page.I am using the Custom thread pool as given in the article's sample. Implementation: =============== In AsyncPage.aspx I inhereted AsyncPage class instead of System.Web.UI.Page. SyncPage.aspx is like any other Web page which inherits
0
2344
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect to application server, I did not get the result in the C# client side, I used a soap monitor to look at the SOAP messages that were exchanged, I can see server returned a correct SOAP message, but the C# client failed to deserialize the XML...
10
2200
by: William L. Bahn | last post by:
I'm looking for a few kinds of feedback here. First, there is a program at the end of this post that has a function kgets() that I would like any feedback on - including style. Second, for those that are interested, I present an outline of the approach I am looking at using in class this semester. I would be very interesting in any feedback on that, but if you are not interested, feel free to skip over it.
2
2547
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now having to integrate some Web services into the application using the existing architecture. These Web services are secured using Forms Authentication. Hence, we need to turn the default behavior of Forms Authentication (redirects to login pages, etc)...
1
2792
by: Elie Medeiros via .NET 247 | last post by:
Hi there, I have written a custom validator function to validate a datefrom a user-filled field. The function tries to parse the dateand if it can't, sets (serverValidateEventArgs)e.IsValid tofalse. The twist is that it allows blank dates to be entered - viz,e.IsValid==true if the field is left blank. The idea is to usethat validation control to make sure the date a user has enteredis valid, without the date field being required to...
4
4514
by: hellrazor | last post by:
Hi there, I'm trying to consume a web-service that is supposed to return a collection of a custom object. The web-service was not created with C# or VS.net. It was created with IBM VisualAge Smalltalk 6. I haven't had problems consuming other web-services but c# seems to choke with "Collection" return types. The collection (or array) is supposed to contain three instances of a custom object called PsmWsResult, which has two variable...
8
5291
by: Tomasz | last post by:
Hello Developers! I have an interesting problem using my custom MembershipProvider, RoleProvider and Forms Authentication. Both MembershipProvider and RoleProvider require session state, where some very important context data are stored during the Session_Start event. My MembershipProvider and RoleProvider depend on this information. It seems that authentication process works with no problems.
0
1837
dmjpro
by: dmjpro | last post by:
I am calling two methods having request object. In two method I am retrieving ServletInputStream using request.getInputStream. For first method call it's working fine but for second method call it's not working. ..... ..... method1(request); method2(request); .....
0
1386
by: Jordan S. | last post by:
Using .NET 3.5... in a "plain old" .aspx page I have the following code in the Init event: this.Context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(60)); this.Context.Response.Cache.SetCacheability(HttpCacheability.Public); this.Context.Response.Cache.SetValidUntilExpires(false); It works great. Testing shows that the page is cached for 60 seconds as expected. Specifically, I insert the current date/time into the Response...
0
9691
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
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
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
10279
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
10036
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...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
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
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2948
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.