how to implement a server on iPhone - ios

Assuming I have implement that :
making my app as a server which means in safari I can connect to the app if I input http://url-link.
My question is : if I request http:// url-link/doc, and the server - that is my app can return the content in document directory.
I don't know how to write the web service in iPhone.
As I'm fresh to web service, can any one help me?
thanks

This is one possibility: Cocoa HTTP Server. From the project's page:
So with Apple's framework for an HTTP
server tucked under our arm we set out
to make our own. We wanted the
following:
Built in support for bonjour broadcasting
IPv4 and IPv6 support
Asynchronous networking using standard Cocoa sockets/streams
Digest access authentication
TLS encryption support
Extremely FAST and memory efficient
Heavily commented code
Very easily extensible
You can link this library from your app and effectively make it a mini-web server.

Related

iOS 3rd Party Framework assure no network connections

In a project we are currently working on we need to rely on a precompiled 3rd party framework.
Is there any way to assure that it is not able to open up a network connection and send out confidential data?
Edit:
To make this a little clearer: It does not have to be at runtime. A static check is fine. I was more thinking something along the lines of: Is there a library that everyone who wants to use network has to link against?
Yes, there is a way to accomplish what you want. Check mitmproxy out. Install mitmproxy on your mac windows or whatever, install your app on the device, launch mitmproxy on the terminal, make your computer's IP a proxy on the device, install https certificate as described on mitmproxy docs, launch you app, and enjoy! mitmproxy can show all outgoing connections from your app. Good luck!
EDIT
Starting from iOS 9, you can set trusted hosts in the app Info.plist under App Transport Security Settings key. More info about it you can find here. Hope this was helpful.
I'm not sure it is possible to ensure an app never makes a network call.
As Fahri Azimov suggests, you could test whether the 3rd party framework makes network calls by funnelling all traffic from test devices through a proxy. You can do this locally on you Mac using the iOS Simulator and Little Snitch. But this cannot ensure that the framework will Never make a network call.
A work-around to ensure no your app performs no networking could be to use NSURLProtocol to intercept any network calls and return errors. You could look at the OHHTTPStubs framework for inspiration. But, again, this is limited as it will only catch NSURLConnection / NSURLSession networking calls, it won't intercept low-level networking operations which the framework could make.

What is GCDWebServer for?

I have a problem when loading the local web from WKWebView in iOS8. There are some suggestions that I should use GCDWebServer. I read through GCDWebServer, but not really understand what GCDWebServer is for on mobile application's side.
Could you give me any practical case of using this library? Sorry for my ignorance.
It's a webserver that you can run on your iOS device. Just like you would run a webserver on VPS or dedicated server providers.
This webserver that you would run and host from your iOS app will of course be available only in the network your iOS device is connected to.
This makes it useful for you to write client programs or scripts on other machines but connected to that network, to call your iOS app (running the GCDWebServer) to upload or download files that you so choose to store in your iOS app's sandboxes document directory for instance. Or as simple as viewing HTML or other data - plain text or json - served by GCDWebServer.
It had nothing to do with what WKWebView. WKWebView is a 'simplified WebKit browser client' that you can implement in your iOS app to view web pages served from other webserver hosts.
You can think of WKWebView as the complete opposite of GCDWebServer.
We can use GCDWebServer has a network interceptor in ios. You can intercept any HTTP requests happening inside WKWebView. For example, you can use GCDWebServer to handle caching and parallel processing for your expensive API requests. You can immediately return some cached responses and later redirect the URL to the actual destination.

Listening to HTTP requests in iOS

Is there a way to intercept HTTP requests in the iPhone? e.g. something in the NSNotificationCenter I can register for so my app would get notified each time an HTTP request will go out or an HTTP response will come in?
I searched a lot but no luck,
Thank you
no you cant intercept HTTP requests with your app - you can of course act as a proxy for your OWN app's request but you cant proxy other apps' requests
From your question its not clear what you want to do, but i would suggest either implementation NSURLProtocol class or using PonyDebugger.
NSURLProtocol:
Create a subclass of NSURLProtocol class that will handle all web protocols such as HTTP, HTTPS, SSL etc. This is a abstract class that provides the basic structure for performing protocol-specific loading of URL data.
Once your created your custom URL protocol, register it in appDelegate class so your protocol will have priority over any of the built-in protocols.
[NSURLProtocol registerClass:[MyURLProtocol class]];
PonyDebugger:
if you just looking to intercept all your http request i would try this tool. PonyDebugger is a remote debugging toolset. It is a client library and gateway server combination that uses Chrome Developer Tools on your browser to debug your application's network traffic and managed object contexts.
AFNetworking:
if your using the very popular AFNetworking for your network request they automatically send notification. try to register the following two:
AFNetworkingTaskDidResumeNotification
AFNetworkingTaskDidCompleteNotification
Do you just want to view all of the HTTP/HTTPS traffic going to / from a single device that you have control of (e.g for debugging purposes)? If so, just setup a proxy and use that to monitor the requests.
If you're talking about building this into an app for general release, I'd very much hope this wasn't possible, and that if it was, I'd suspect it wouldn't make it through app store approval.
If you just want a debugging proxy:
For Windows, download Fiddler (free), and use your and follow the instructions here (install a cert on your phone and use the IP address of the machine running Fiddler as the proxy address):
http://docs.telerik.com/fiddler/configure-fiddler/tasks/ConfigureForiOS
For Mac OSX, Charles will also do the job (I've used it for this purpose and it works well):
http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/

inspect http requests in ios simulator/devices

I am working on an ios app which communicate with the server via http request. And I want to monitor the network traffic when testing my app in ios simulator/devices.
Is there any software or tools I can used to inspect the http requests of a specified application on mac/ios, just like firebugs for web developers?
Thanks.
As far as I know, there are several tools in App Store that provide the network traffic monitor feature. But, they could only view iPhone as a whole and stay at that level. In other words, they could only tell how much traffic has been consumed of this iPhone. For each app? No data.
You can use HTTP Catcher to capture web traffic. It's a Web debugging proxy for iOS, so you can view requests and responses directly on iPhone.
You can use Proxyman to record/capture all the requests & responses from your app while developing.It will support ios simulators also. Without doing any code change we use this.
First Download the Proxyman app form the above link after that just go through this documentation for references.
Charles has recently released an iOS version for http traffic monitoring. it is a paid app though. Good news is that you can set up Charles free desktop version then setup HTTP proxy from your iOS device.

Blackberry application to establish an http connection

i have been working on developing an blackberry application. as per now i want the application to connect to a local server on my network and fetch a file from that machine. i have been using the library given by a named blackberry developer Mr.peter strange....here is the link for the same Http connection through BIS-B
my requirement would be setting up connection to the local server using any transport mode but it should be able to render the text downloaded.
i tried using the demos provided by blackberry samples as it comes with the plugin for eclipse the http demo from those samples shows only trying to setup an http connection string and the networkapidemo sample shows diffrent http codes when the url is entered as desired.i am running all the applications on the simulator. i havent tried running any of my apps on the hardware
may i know why this problem arises of http codes....ill also want to know guidelines about how to set a simple http connection just to download a file(text file) from a local server.
I have tried many forums too. if anybody would have a look at it i would post it here.
Only a simple connection is becoming a headache!
anyways...waiting for replies..
thanx in advance guys :)
It does not matter whether you want to communicate with local or remote server.
1) See the API docs on HttpConnection. There are sample code in there.
2) Unfortunatelly, on BB you should be aware of Network Transports. Check this thread to get all info you need on Network Transports.
UPDATE:
The second point explains an approach that will work on any OS. If you need an OS 5+ only approach, then check the ConnectionFactory API. ConnectionFactory usage sapmles.

Resources