I have requirement of having proxy server where request from browser will be forwarded to my custom proxy server. Afterwards Proxy server will read request from client and talk to requested resource using some thing like this --
HttpWebRequest request =(HttpWebRequest)WebRequest.Create ("http://www.google.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
then once I have response back in response object write returned HTML to browser , at this point I am stuck and do not know how to write information to browser ?
Can someone please help ???
Related
I am new at web development, so how to make http request\respone for some site (http://google.com)
Thank you!
P.S.
I mean, that when my SomeController activated- i want send http request to another site,get data from it and send it into View
A client (browser) submits HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and also contains the requested content. GET - requests data from a specified resource, http://google.com - you type this url in browser and hit the enter key, it's a get request and you see a page, that the response.
Click here for details.
Use HttpClient to connect a site from your mvc controller, click here for details.
I have a url which sends sms to the provided mobile numbers. I want to just call this url from windows application but not to open in browser. I just want to execute that url from my windows application.
example of url
http://mycompany.com/sms.aspx?mobilenum=9123444777&Message=this is a test message
I have tried in this way. But it is opening in a browser.
I dont want this to be opened in a browser. I just want to execute this line internally.
System.Diagnostics.ProcessStartInfo sInfo = new
System.Diagnostics.ProcessStartInfo("http://mycompany.com
/sms.aspx?mobilenum=9123444777&Message=this is a test message");
System.Diagnostics.Process.Start(sInfo);
Thanks.
Have you tried to use a HttpWebRequest?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(#"http://mycompany.com/sms.aspx?mobilenum=9123444777&Message=this%20is%20a%20test%20message");
WebResponse response = request.GetResponse();
response.Close();
You can't "execute" url like that... URL is an address of a resource that you can use only by sending a request to the remote server. So instead you want to post data using a query string (make an HTTP request). You can achieve that for example by using WebClient class...
http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.110%29.aspx
I am using upload file method of web client to post transaction to a particular URL. I am using wireshark to capture this network communication, but surprisingly wireshark is not showing this requested URL in my UAT System. As it is a HTTP Request I have filtered it with particular Ip address and Http and it is showing all other request which I am doing through my web browser but not particular request which I am doing through my webclient class.
Sample Code :-
string url = ConfigurationSettings.AppSettings["https_url"];
WebClient wc = new WebClient();
wc.QueryString = q;
string ResultString = string.Empty;
byte[] postBytes = wc.UploadFile(url, "POST", strFileName);
If I am understanding your code correctly, your are uploading your file via HTTPS? If that is the case, your traffic will only show up as SSL(which will not be filtered as HTTP) unless you configure your wireshark to decrypt SSL traffic correctly.
Some information: http://wiki.wireshark.org/SSL
If you don't want to deal with setting up wireshark to decrypt HTTPS traffic, I recommend tweaking your url to send a POST via http, which will then show up in your wireshark sniff.
I have Managed to Setup II7 with Gzip Compression .
I can check via web sniffer that my asmx web service encoding is Gzip but how to i enable
gzip Compression on my C# Client , i am using the Web Service is Service reference in my application.
Actually i am trying to send large amount of data , 10k objects of array so Compression with be great effect on bw.
but how do I enable Compression on my C# Client.
i am trying to see that many people sees same problem but there nothing clear answer some says use third party tools or some says about custom headers etc etc .
is not there any proper way , built in to consume Compressed web service
As #Igby Largeman pointed out, you can use your IIS7 to enable the compression on the server, but this is not enough.
The main idea is to set the headers on the client side and server side:
Client:
Accept-Encoding = "gzip, deflate";
You can achieve this by code:
var request = HttpWebRequest.Create("http://foofoo");
request.Headers["Accept"] = "application/json";
request.Headers["Accept-Encoding"] = "gzip, deflate";
or
var request = HttpWebRequest.Create("http://foofoo");
request.AutomaticDecompression = DecompressionMethods.GZip |
DecompressionMethods.Deflate;
If you use some WCF client, and not the HttpWebRequest, you should use custom inspector and dispatcher, like in this article:
So I used a message inspector implementing IClientMessageInspector and IDispatchMessageInspector to automatically set the AcceptEncoding and ContentEncoding http headers.
This was working perfectly but I could not achieve to decompress the response on the server by first detecting the ContentEncoding header thus I used the work around to first try to decompress it and if it fails just try to process the request as normal.
I also did this in the client pipeline and this also works.
Server:
// This is the nearly same thing after all
Content-Encoding = "gzip" OR Content-Encoding = "deflate"
To do this on the Server side, you should enable httpCompression in the IIS.
I think you should check the original article to get this work
There is a web service that can only be consumed via http and a client that can only consume https web services. Therefore I need some intermediary that forwards on requests received in https and returns responses in http.
Supposing that the intermediary is completely dumb save for the fact that it knows where the web service endpoint is (i.e. it doesn't know what the signature of the service is, it just knows that it can communicate with it via an http web request, and it listens on some https uri, forwarding on anything it receives), what is the most simple way of achieving this?
I've been playing around with this all day and am not sure how to achieve the "dumb" bit, i.e. not knowing the signature for passing back the verbatim response.
A dumb intermediary is essentially a proxy. Your best bet might to be just use standard asp.net pages (instead of shoehorning into service functionality like ASMX or WCF which are just going to fight you) so you can receive the request exactly as-is and process it in a simple way using standard request/response. You can make use of HttpWebRequest class to forward the request on to the other endpoint.
Client requests https://myserver.com/forwarder.aspx?forwardUrl=http://3rdparty.com/api/login
myserver.com (your proxy) reads querystring forwardUrl and any POST or GET request included.
myserver.com requests to http://3rdparty.com/api/login and passes along GET or POST data sent from the client.
myserver.com takes response and sends back as response to other endpoint (essentially just Response.Write contents out to the response)
You would need to write forwarder.aspx to process the requests. Code for forwarder.aspx would be something like this (untested):
protected void Page_Load(object sender, EventArgs e)
{
var forwardUrl = Request.QueryString["forwardUrl"];
var post = new StreamReader(Request.InputStream).ReadToEnd();
var req = (HttpWebRequest) HttpWebRequest.Create(forwardUrl);
new StreamWriter(req.GetRequestStream()).Write(post);
var resp = (HttpWebResponse)req.GetResponse();
var result = new StreamReader(resp.GetResponseStream).ReadToEnd();
Response.Write(result); // send result back to caller
}