How to specify the source port for an http request in iOS

醉酒当歌 提交于 2019-12-11 08:57:58

问题


I know that it's an unusual thing to need to do, but I need to specify the SOURCE port to be used in an outgoing http(s) request in iOS. I know that there are many different 'standard' ways to send http(s) requests -- from what I understand the most usual involve NSURLConnection and NSURLSession, but I couldn't see if I can specify the source port. Is it possible to somehow use a socket interface to create the socket and then use this socket with NSURLConnection or NSURLSession?

Or perhaps (as a hack) can one specify the ephemeral port range that my app can use (so I'll restrict it to a range of 5 or 10 ports)?

As a last grasping at straws: is there some ip masquerading or other rules that are available on the iOS device that the app could use to ensure that the source port is correct? (I suppose one could write a process which just does masquerading by hand to the correct fixed port -- essentially write a local http forwarding proxy -- is that my only possibility?)

I don't need any fancy feature or control of these http(s) requests except that they need to come from a certain very narrow range of port numbers.

thanks very much.

If you want to ask why I have such a stupid requirement, please feel free to ask privately -- but don't clutter up this question. THanks!!

I note that just a year ago, iOS: how to get the http connection's source port was asked, but that asked about READING the ephemeral port chosen by the system.

thanks

来源:https://stackoverflow.com/questions/31060498/how-to-specify-the-source-port-for-an-http-request-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!