Why is System.Net.WebRequest unsupported in iOS?

本文探讨了在iOS项目中使用System.Net.WebRequest遇到NotSupportedException的问题。由于Unity主要支持WWW请求方式,作者提出了一些替代方案,包括使用System.Net和TCP Socket自行实现HTTP请求,或者通过原生代码插件使用NSURLRequest。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问:


Using System.Net.WebRequest on an iOS project results in a NotSupportedException.

Why is this? This is really crippling from my point of view, and really limits what can be done with web services within a Unity game. 

Please don't tell me to use WWW, I can't even read a HTTP status code that, or set headers...

Is there a way around this, or am I going to be forced to write my own WebRequest class?


答1:

Okey so I'm not telling you to use WWW, you can always use System.Net and TCPSockets to pull it off yourself. The HTTP protocol is extremely easy actually.
Alternatively a native code plugin to NSURLRequest allows you to do it too.

As for WWW:
WWW uses the native NSURLRequest on iOS, the best and most stable form of request you can do.

.Net.WebRequests are basically nowhere supported by Unity (aside of perhaps standalone win / osx) as it focuses its usage on WWW which complies to the limitations of the various platforms (aot on iOS, security sandbox on webplayer etc), a thing that is not the case for WebRequests.


答2:

OK. Here is one laptop-battery-charge worth of coding. It still has a way to go, but it is starting to work.

http://code.google.com/p/unityweb/source/checkout

This project provides a replacement HTTP.Request class for Unity3D, based on System.Net.TcpClient, using Asynchronous IO.

TODO: Add proxy support, Gzip decompression, documentation and examples.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值