Modify Request Header without Using Proxy

how to modify request header without using proxy. I have tried IdMappedPortTCP (Indy v9) but fail :(

procedure TForm1.Button1Click(Sender: TObject);
begin
//  TCP.MappedHost:= '128.199.134.171';
//  TCP.MappedPort:= StrToInt('80');
  TCP.Bindings.Add.IP:= '127.0.0.1';
  TCP.Bindings.Add.Port:= StrToInt('3001');
  TCP.Active:= True;
end;

procedure TForm1.TCPExecute(AThread: TIdMappedPortThread);
begin
  Athread.NetData:= StringReplace(Athread.NetData, 'http://www.xyz.com/panel', 'http://www.xyz.com/temporaryPanel', [rfReplaceAll]);
end;
0
Adam
8/18/2015 7:52:28 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

2 Replies
502 Views

Similar Articles

[PageSpeed] 30

Adam wrote:

> I have tried IdMappedPortTCP (Indy v9) but fail :(

Well, in order to even see the connection, the client has to know to connect 
to your server instead of the real server.  So either the client hass to 
be configured to treat your server as a proxy to the real server, or the 
client has to be configured as thinking your server *is* the real server. 
 Which do you want?  Either way, the client has to be configured accordingly. 
 You cannot intercept its connections otherwise.

> TCP.Bindings.Add.IP:= '127.0.0.1';
> TCP.Bindings.Add.Port:= StrToInt('3001');

You are making a classic newbie mistake - you are adding *two* bindings and 
setting them to different IP/Port pairs.  You need to add *one* binding instead:

{code}
procedure TForm1.Button1Click(Sender: TObject);
begin
  TCP.Active := False;
  TCP.Bindings.Clear;
  with TCP.Bindings.Add do
  begin
    IP := '127.0.0.1'; // if you have multiple NICs, you can set this to 
'' to accept connections on all of them...
    Port := 3001;
  end;
  TCP.Active:= True;
end;
{code}

Or:

{code}
procedure TForm1.Button1Click(Sender: TObject);
begin
  TCP.Active := False;
  TCP.Bindings.Clear;
  // if you have multiple NICs, this approach accepts connections on all 
of them...
  TCP.DefaultPort := 3001;
  TCP.Active:= True;
end;
{code}

> procedure TForm1.TCPExecute(AThread: TIdMappedPortThread);
> begin
> Athread.NetData:= StringReplace(Athread.NetData, 'http://www.xyz.com/panel', 
'http://www.xyz.com/temporaryPanel', [rfReplaceAll]);
> end;

This is not a viable solution, for a number of reasons, not the least of 
which is that TIdMappedPortTCP passes through raw arbitrary data, and as 
such NetData is not guaranteed to even hold a complete request each time 
it is triggered.  You need to implement a streaming HTTP parser on top of 
this event.  Each time the event is triggered, copy the current NetData into 
a running buffer of your choosing, clear the NetData to prevent partial transmissions, 
parse the buffer extracting only complete requests, and modify them as needed 
before saving them back to the NetData for transmission.

-- 
Remy Lebeau (TeamB)
0
Remy
8/18/2015 11:23:53 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Adam wrote:
> 
> > I have tried IdMappedPortTCP (Indy v9) but fail :(
> 
> Well, in order to even see the connection, the client has to know to connect 
> to your server instead of the real server.  So either the client hass to 
> be configured to treat your server as a proxy to the real server, or the 
> client has to be configured as thinking your server *is* the real server. 
>  Which do you want?  Either way, the client has to be configured accordingly. 
>  You cannot intercept its connections otherwise.
> 

if possible I want to
request ~> modify ~> server
instead of
request ~> modify ~> proxy ~> server

> > TCP.Bindings.Add.IP:= '127.0.0.1';
> > TCP.Bindings.Add.Port:= StrToInt('3001');
> 
> You are making a classic newbie mistake - you are adding *two* bindings and 
> setting them to different IP/Port pairs.  You need to add *one* binding instead:
> 
> {code}
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   TCP.Active := False;
>   TCP.Bindings.Clear;
>   with TCP.Bindings.Add do
>   begin
>     IP := '127.0.0.1'; // if you have multiple NICs, you can set this to 
> '' to accept connections on all of them...
>     Port := 3001;
>   end;
>   TCP.Active:= True;
> end;
> {code}
> 
> Or:
> 
> {code}
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   TCP.Active := False;
>   TCP.Bindings.Clear;
>   // if you have multiple NICs, this approach accepts connections on all 
> of them...
>   TCP.DefaultPort := 3001;
>   TCP.Active:= True;
> end;
> {code}
> 

thanks, I use first code. it look more clean :D

> > procedure TForm1.TCPExecute(AThread: TIdMappedPortThread);
> > begin
> > Athread.NetData:= StringReplace(Athread.NetData, 'http://www.xyz.com/panel', 
> 'http://www.xyz.com/temporaryPanel', [rfReplaceAll]);
> > end;
> 
> This is not a viable solution, for a number of reasons, not the least of 
> which is that TIdMappedPortTCP passes through raw arbitrary data, and as 
> such NetData is not guaranteed to even hold a complete request each time 
> it is triggered.  You need to implement a streaming HTTP parser on top of 
> this event.  Each time the event is triggered, copy the current NetData into 
> a running buffer of your choosing, clear the NetData to prevent partial transmissions, 
> parse the buffer extracting only complete requests, and modify them as needed 
> before saving them back to the NetData for transmission.
> 
> -- 
> Remy Lebeau (TeamB)

thanks again Lebeau, but I want focus on proxy problem. so I cant implement it right now
0
Adam
8/19/2015 2:28:44 AM
Reply:

Similar Artilces:

Modify Http Request Header using JavaScript
Hi,    The question might look trivial to many of you, anyway can you guys provide with a Yes/No answer along with some reasoning. 1. Can we modify the HttpRequest on client side by using Javascript to append our custom httpheaders to the request. 2. Is there any other way to append custom httpheaders to the request from the client side? -Amrish   Hi,Thank you for your post!Can we modify the HttpRequest on client side by using Javascript to append our custom httpheaders to the request.See Setting HTTP request headersExample Codevar headerName = "X-hello...

set request header in CONNECT request to (https) proxy server?
Hi - I apologize in advance if this is an elementary question; I have searched the docs and the list and haven't found an answer yet. I understand how one can modify the outgoing request to add headers by monitoring the http-on-modify-request topic; this is well documented. What I can't figure out, though, is how to add a request header that is sent to the proxy server. Obviously for non-HTTPS traffic, a request to the proxy server looks pretty similar to a regular HTTP request, so the proxy server could extract my custom header. With HTTPS traffic, however, we have just...

[PATCH] warning at use of /c modifier without /g modifier
It makes no sense to use /c without /g, right? As best I can tell, such a /c is ignored. The appended patch creates a warning: % perl -w -e '"x" =~ m/foo/c' Use of /c modifier is meaningless without /g at -e line 1. Jeffrey --- bleedperl.orig/pod/perldiag.pod Fri Mar 22 01:40:12 2002 +++ bleedperl/pod/perldiag.pod Tue Mar 26 15:40:11 2002 @@ -3874,6 +3874,12 @@ (W untie) A copy of the object returned from C<tie> (or C<tied>) was still valid when C<untie> was called. +=item Use of /c modifier is meaningless without /g + +(W...

Modifying Request Headers
when i try to modify the request headers i get this error message: "Operation is not supported on this platform." here is what i am trying to do:  System.Uri url = new System.Uri(Request.Url, Request.ApplicationPath); System.Web.HttpRequest request = new System.Web.HttpRequest(Server.MapPath(url.LocalPath), url.ToString(), url.Query); request.Headers["Credentials"] = EncryptCredentials(System.IO.File.ReadAllText(System.IO.Path.GetPathRoot(Server.MapPath("."))+"Public Key.xml"), username, password); System.Web.HttpResponse response = new Sys...

[PATCH 5.7.3] warning at use of /c modifier without /g modifier
Jeffrey Friedl sais: > You had strong feelings about the category, so I thought I'd ask if > you'd like to do this.... So I did. 1. This should be applied instead of the patch Jeffrey sent earlier this evening. 2. The funny thing about Jeffrey's patch was that although he put the warning in the 'misc' catehory, he had documented it as being in the 'regexp' category. This patch fixes the code to agree with the documentation. 3. All the relevant tests pass. 4. The other funny thing about Jeffrey's patch was that it also ad...

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there ...

superreview requested: [Bug 362014] Cocoa widget theme code uses 10.4-header bits and local system headers : [Attachment 246853] fix v1.0
Josh Aas <joshmoz@gmail.com> has asked Mike Pinkerton <mikepinkerton@mac.com> for superreview: Bug 362014: Cocoa widget theme code uses 10.4-header bits and local system headers https://bugzilla.mozilla.org/show_bug.cgi?id=362014 Attachment 246853: fix v1.0 https://bugzilla.mozilla.org/attachment.cgi?id=246853&action=edit ...

superreview requested: [Bug 257758] Add UI for WPAD and option for using the configured SOCKS proxy for DNS lookups to proxy preferences : [Attachment 170779] Patch V1.3
Stefan Borggraefe <Stefan.Borggraefe@gmx.de> has asked Mike Shaver <shaver@mozilla.org> for superreview: Bug 257758: Add UI for WPAD and option for using the configured SOCKS proxy for DNS lookups to proxy preferences https://bugzilla.mozilla.org/show_bug.cgi?id=257758 Attachment 170779: Patch V1.3 https://bugzilla.mozilla.org/attachment.cgi?id=170779&action=edit ------- Additional Comments from Stefan Borggraefe <Stefan.Borggraefe@gmx.de> Neil is right. I made a mistake when testing the locked prefs. ...

superreview requested: [Bug 297573] Modify JSS tests such that they access certs from platform specific directories : [Attachment 186564] Modified JSS/JSSE Client-Server tests to use platform specifi
Sandeep Konchady <Sandeep.Konchady@Sun.COM> has asked glen beasley <glen.beasley@sun.com> for superreview: Bug 297573: Modify JSS tests such that they access certs from platform specific directories https://bugzilla.mozilla.org/show_bug.cgi?id=297573 Attachment 186564: Modified JSS/JSSE Client-Server tests to use platform specific cert directory https://bugzilla.mozilla.org/attachment.cgi?id=186564&action=edit ------- Additional Comments from Sandeep Konchady <Sandeep.Konchady@Sun.COM> Modified JSS/JSSE client server tests to use platform specific cert direc...

focus event using http request or xml request using javascipt
i want lost focus event using http request or xml request using javascipt how to call code file (.cs file) using ajax and javascript i have one asp.net server control  Nothing is really over,untill the moment stop trying for it...Amitsp(MCTS,MCP)sqlreporting.blogspot.com You can capture the event in the javascript and then call the cs function in the page from the javascript. You can also call the button in the page (with style=display:none) . In the javascript you can call the click event of the button which will call the server side code.Vikram www.vikramlakhotia.comPlease mark the...

Assigning a soap header using proxy
Hi All, I am using a proxy of the web service to connect to the webservice , now i want to assign a soap header to the request , how can this be done. Please post any code snippets regarding this.   Regards Suresh Kumar Goudampally    Hi Suresh, I belive you are using HttpWebRequest to call the web service.  If that is the case follow the code below.    private static HttpWebRequest CreateWebRequest(string url, string action)    {        HttpWebRequest webReques...

do all servers make use of the not-modified header?
I am writing a boommark manager application that uses a http handler to periodically poll web servers - one feature the app provides is the ability to let users know if one of their bookmarked web pages have been updated. My approach is to use the remote servers 304 status as an indication that the page has not been modified. But can I assume that a remote page has been modified simply becuase the server did not send the 304 header? Is it likely that  that some server simply don't make use of this header?? In which case I m left with a feature that will correctly flag modifie...

Modify Request Headers with HTTP module?
HiI need to authenticate a flash client. Flash is limited in what I can programmatically set in terms of HTTP headers etc. I planned to pass in the ASP.NET session id into the flash control. The flash control would then make a request to a .NET webservice. I need to pass the sessionid from the flash client to the server. I then need to check that the session is valid on the server.My idea was to create an HTTP module which would look for the sessionid (passed as part of the SOAP request, or otherwise). It would then ADD an HTTP header to the request "ASP_sessionid" or whatever, with the sess...

Server requests without using UpdatePanel
I've been using Michael Schwarz ajax library for a while.  One thing that's nice about it is the ability to make direct server callbacks without any type of UI.  You just register the server function in server-side code, which then makes those functions available to the client.  You can send and receive data when calling the server-side functions, and call them synchronously or asynchronously.  Is there a way to do this easily with asp.net ajax?  I looked through the docs for a while, but didn't see anything readily. Thanks Use Webservices together with JSON, it i...