question

giorgiotino avatar image
giorgiotino asked

HttpWebRequest Proxy set to null?

I have just found out that if I use RequestType.UnityWebRequest then I can see the traffic through Charles proxy without problem (I have setup SSL as well, so I can see everything in clear) BUT if I switch to RequestType.HttpWebRequest then all of a sudden I don't see traffic from Unity to PlayFab. By looking at the code, I see that in

PlayFabWebRequest, method Post(), lines 303 and 313 the HttpRequest.Proxy variable is set to null:

reqContainer.HttpRequest.Proxy = null;

this probably overrides the system proxy, as if I comment those lines out I see the requests in Charles without problems.

(In case you ask it: I wish I could use the UnityWebRequest BUT this does not actually use the RequestTimeout at all, that's why we switched to HttpWebRequest)

I have two questions:

1) Why is this value set twice? Sounds like a "bug"
2) Why is Proxy set to null in the first place? Is it safe to not set it to null and let it use the default system proxy settings?

All I see is a comment stating:

// Prevents hitting a proxy if no proxy is available. TODO: Add support for proxy's.

but it's weird as this basically prevents any proxy to be used...

apisunity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> 1) Why is this value set twice? Sounds like a "bug"

It is a piece of redundant code that doesn’t cause any major problems. You can comment it according to your needs. Apologies for the confusion.

>> 2) Why is Proxy set to null in the first place? Is it safe to not set it to null and let it use the default system proxy settings?

As this .Net documentation -- Automatic Proxy Detection said, “For requests that you create, you can disable automatic proxy detection at the request level by using a null Proxy with your request. Requests that do not have a proxy use your application domain's default proxy, which is available in the DefaultWebProxy property.”

Generally, Proxy is set to null to avoid the initial delay caused by automatic proxy detection. Some external threads -- Why is this WebRequest code slow? mentioned this point. You can set the Proxy manually based on your requirements. More details about the HttpWebRequest Proxy configuration, please refer to the .net documentation Accessing the Internet Through a Proxy.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

giorgiotino avatar image giorgiotino commented ·

Sarah,

thanks for the response, this clarifies everything. I wish there was a way to set this value through the PlayFabSharedSettings (maybe this is what that comment refers to?) so I don't have to modify PlayFab internal code, but at least I know it's not harmful and I can set the Proxy for my tests without problems.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.