How to debug Json between Local IIS Website and Local - rest

I'm really struggling to know what the problem is here...
I have 2 websites configured in IIS...
**PH.Website** (STANDARD MVC PROJECT)
**PH.Api** (MVC WEB API PRIOJECT)
When you hit the PH.Website it uses a WebClient class in one of the controllers to download data from the PH.Api. However fiddler only sees traffic going to the PH.Website not the PH.Api.
After reading around on the internet I apparently have to do some configuration of the Syste.Net in the Web Api Project. So I added...
<system.net>
<defaultProxy>
<proxy
usesystemdefault="False"
bypassonlocal="True"
proxyaddress="http://PH.Api"
/>
</defaultProxy>
</system.net>
But still no luck. I know the request is happening I just cant see it.
Whats even more confusing is when I configure Fiddler to use Port 80 its says it cannot listen on that port. But hang on if it cant listen on 80 then how the hell can it see traffic on the Http port:80 anyway?
P.s. I really need to be able to run multiple sites locally so. I hate running sites under Localhost or 127.0.0.1 seems so silly when you can create seperate sites for everything in IIS and know exactly where everything maps....

Let's back up.
Fiddler's a proxy server; it sees all of the traffic that is sent to it. Generally speaking (unless you're using it as a Reverse Proxy) you never want to configure Fiddler to run on port 80; instead leave it up at port 8888 where it runs by default. You instead configure your client to proxy its traffic through Fiddler.
Now, what "reading around on the Internet" did you do that caused you to modify your machine.config or web.config file (you didn't mention which you edited)?
If your goal is to watch traffic with Fiddler, you need to point the ASP.NET proxy settings at Fiddler, not at whatever "PH.api" is (e.g. use "127.0.0.1:8888" and set bypassOnLocal to false). The further complexity arises in that System.NET bypasses the proxy for any request to "localhost" or "127.0.0.1", so if you're using those addresses for your target, you should change them to "localhost.fiddler" temporarily while debugging.

Related

gethostbyname not working for external server

I am writing an application with C++ to connect to my server.
I am using gethostbyname(). It is working fine when I give host name as 'localhost'. but if i try any other site like google.com, it fails.
Can anyone please tell me what could be going wrong.
I can access those websites through browser. Note: I have proxy set up in my browser.
Is thr proxy causing issue with gethostbyname()? if yes, how can I mention proxy in my C++ code?
Based on what you describe in your question, it appears that your machine is on a corporate network that is firewalled off the Internet, all access to the web is via a web proxy, and that your network does not have Internet DNS resolution.
Even if you managed to succeed in resolving an IP address, you will not be able to make an outbound connection, unless your firewall offers a Socks proxy, or an equivalent.
If your intent is to write a client that accesses web sites via HTTP, you will need to use your corporate HTTP proxy to do that. Contact your system administrator for more information.

How can I monitor HTTP traffic from BlueStacks?

I want monitor HTTP traffic from BlueStacks so that I can debug web analytics tracking - any idea how?
For example, my application calles my server. I want to know what actual API my application actually called during testing.
I do not see any HTTP requests in Fidller even when using the BlueStacks.
I thought fiddler capture all internet request done by any software.
Actually you can use fiddler. You see, fiddler configures the winINET proxy to go through it (the one used by internet explorer and all other microsoft software, but sometimes even third pary software uses winINET proxy config - that is why some programs just magically work with fiddle). Some programs ignore wininet config completly and have their own method of setting a proxy (like firefox, chrome). And other programs, like bluestacks, have no support for proxy at all.
But you can force BlueStacks to go through the fiddler proxy. A tool which can do that, and which has a tutorial on this, is ProxyCap:
http://www.proxycap.com/bluestacks.html
Just use 127.0.0.1 as server and 8888 as port number in configuration of the proxies in proxycap. You must also add HD-Agent and HD-Frontend executables in the rules, as specified in the last part of the step-by-step guide.
Unfortunately, proxycap is a 30 day trial. You can use free proxifiers out there. Find something that supports http.
http://en.wikipedia.org/wiki/Comparison_of_proxifiers
I did manage to make this work with proxyCap myself and haven't tried anything else yet.
I think this is better for http traffic sniffing than wireshark which is for lower level network sniffing
Use ProxyCap to let Fiddler capture the trafic.
ProxyCap forwards all Bluestack communication to HTTP proxy (in this case our proxy is Fiddler).
The full step-by-step guide, how to redirect the Bluestack application traffic through proxy, is HERE.
Use 127.0.0.1:8888 as proxy address. That is the address of Fiddler on the local computer.
Today I tried Fiddler - ProxyCap - BlueStacks. It didn't work at first. After I added "HD-Plus-Service.exe" everything was Okay. It seems like new bluestacks versions don't use HD-Network.exe? Anyway my program list includes:
HD-Service.exe
HD-Agent.exe
HD-Frontend.exe
HD-Network.exe
HD-Plus-Service.exe
HD-LogRotatorService.exe
In 2019, Fiddler has been updated to support Proxy, just set up your BlueStacks to use Fiddler's proxy and you can capture all HTTP/HTTPS traffic going out from it.
In addition, for latest Bluestacks3 version here are the list of apps you need to add to your both program lists:
HD-Agent.exe ( from "C:\Program Files\Bluestacks\" )
HD-Player.exe ( from "C:\Program Files\Bluestacks\" )
Bluestacks.exe ( from where you installed Bluestacks )
Fiddler has a documentation regarding how to capture traffic of Android devices: https://docs.telerik.com/fiddler/configure-fiddler/tasks/ConfigureForAndroid. You can use the same config for bluestack

can the different hosts (not ip) forwarding to the same port externally?

Im just wondering, can 2 or more different external hostname/DNS redirect to multiple local servers but same port?
Let's see, I have 2 DNS internet domain for an example, myserver1.com and myserver2.com, and both I have same A record to my forwarded server IP (e.g: 102.123.123.123). Under my server which only has 102.123.123.123 IP address has 2 application servers but instead of trying to make they work, I use different port for each server applications for an example, serverApp1 listening to 0.0.0.0:2010, serverApp2 listening to 0.0.0.0:2020
My point is, is there any way or how to forward my myserver1.com:2000 to serverApp1 (port 2010), and myserver2.com:2000 to serverApp2 (port 2020) but both myserver1.com and myserver2.com has a same A record?
Im quite sure either it is in iptables or /etc/hosts or BIND issues, but guide me if I missed something. And by the way, the servers and DNS records are accessible from the internet which is the firewalls are configured properly. Thanks.
I don't have much experience in that, but I think you will need a third server/firewall/proxy listening for the incoming host and route it accordingly.
Again, I don't have much experience in that, so I'm not sure if the firewall is able to do that.
I think you can use redirection servers like apache.
In my application we want to access lot of intranet servers from internet. So what we did, we configured a apache with all the mappings in httpd.
So when ever a request to apache comes, it will be redirected appropriately.
For example - I have two servers or hostname in intranet : 1) abc.com:7300/context1
2) xyz.com:8900/context2
We configured a apache with host name abcxyz.com:9000. When a request like
abcxyz.com:9000/context1 comes it will be redirected to abc.com:7300/context1 and when a request like abcxyz.com:9000/context2 comes it will be redirected to xyz.com:8900/context2.
In your case since the requests are going through the single server (102.123.123.123), you can use redirection.
Hope it helps.

Using Fiddler with IIS7 Express

I am using IIS7 Express while developing my web application. I need to use fiddler to investigate an issue and cannot figure out how to configure things so I can get the HTTP stream. It seems that IIS7 express will only listen on localhost which means I cannot access the stream.
This has nothing to do with IIS7 Express and everything to do with the fact that you're using loopback traffic.
Ref: https://www.fiddlerbook.com/fiddler/help/hookup.asp#Q-LocalTraffic
Click Rules > Customize Rules.
Update your Rules file like so:
static function OnBeforeRequest(oSession:Fiddler.Session)
{
if (oSession.HostnameIs("MYAPP")) { oSession.host = "localhost:portnumber"; }
}
Then, just visit http://myapp in your browser.
Or use the address http://localhost.fiddler/ and Fiddler will use the hostname localhost instead of converting to an IP address.
One useful variation of Eric's answer (that was edited by Brett) would be to use oSession.port to build the oSession.host. With this little change, if one needs to capture IIS express traffic on http://localhost:12345, they could use http://iisexpress:12345. That will make it easier to capture traffic for sites with random ports as created by WebMatrix and VS. I tried it out with IE and Firefox and capturing IIS Express traffic was a breeze. Fiddler rocks!.
static function OnBeforeRequest(oSession:Fiddler.Session)
{
//...
// workaround the iisexpress limitation
// URL http://iisexpress:port can be used for capturing IIS Express traffic
if (oSession.HostnameIs("iisexpress")) { oSession.host = "localhost:"+oSession.port; }
//...
}
With the latest version of fiddler, you only need to navigate to localhost.fiddler:port. However, doing that alone didn't help me and I was still getting access denied when using Windows Authentication. To fix this, I found this blog entry: http://www.parago.de/2013/01/fiddler-and-the-401-unauthorized-error-with-asp-net-web-api-using-integrated-windows-authentication-wia/
In short, create this key:
Key Path HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\Lsa\MSV1_0
Value Name BackConnectionHostNames
Value Type REG_MULTI_SZ
String Value localhost.fiddler
You can use fiddler as a proxy between your clients and the server. This means you start up fiddler, and then access the server using fiddler's port rather then the usual port (default for fiddler2 is 8888 I think). If you need to debug the server "live" vs. real world clients, you can change the IIS binding from :80 to something else, and place fiddler's proxy on port 80.
EDIT: By the way, by default fiddler2 changes the proxy settings on your browsers so that they access everything through fiddler anyway (on the machine in which fiddler is installed only)

which ASP.NET hosting site allows listening on different ports than 80 and uses .NET 4?

I'm trying to take advantage of HTML 5 web sockets in .NET and the easiest way appears to be something like what this guy does.
I've already tested this myself and it works great, but there are a few problems if I try to deploy this to my hosting site (discountasp.net). Basically, I am not allowed to open up a port on 8080 and listen on it. I then tried to figure out a way to listen on port 80 with IIS as well, but using the HTTPListener, I run into sercurity issues as well. This doesn't seem like it will help since I can't mess with this stuff on the hosting site server either.
So to make my life easier, I think I need to find a hosting site that simply allows me to open up a socket on port 8080 and listen on it. Anyone know of one? Or does anyone know of a workaround (besides sniffing all the traffic on port 80)?