IOS Http Event Listener (Persistent http connection)

Is there a way to create an HTTP listener in IOS

HttpListener: I mean we will create a persistent http channel using Post request and it will send events to that channel. I want to create a channel listening for server events.

-(void)httpPost:(NSString *)url andXml:(NSString *)xml{
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSURL *urls = [NSURL URLWithString:url];
    NSMutableURLRequest *request1 = [[NSMutableURLRequest alloc] initWithURL:urls];
    NSData *postData = [xml dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *username =[[ApplicationStorage applicationStorage] userName];
    NSString *password = [[ApplicationStorage applicationStorage] password];


    //HTTP Basic Authentication
    NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password];
    NSData *authenticationData = [authenticationString dataUsingEncoding:NSUTF8StringEncoding];
    NSString *authenticationValue = [authenticationData base64Encoding];
    [request1 setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];
    [request1 setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];

        [request1 setHTTPMethod:@"POST"];


    [request1 setHTTPBody:postData];

    NSError *error = nil;
    NSHTTPURLResponse *response = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error];
    NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    NSLog(@"httpPostOrPut >>>>>>>>> RESPONSE: %@",newStr);
   // [[NSRunLoop currentRunLoop] run];
}

      

I created a feed using the above request. but the channel is closed immediately after creation

I did it in java

HttpResponse objBwResponse = bwPost(String.format(XML_CHANNEL_CREATION, generateChannelSetId()), getBWServerAddress() + CHANNEL_CREATION_URL);
            if (objBwResponse != null && objBwResponse.getStatusLine() != null && objBwResponse.getStatusLine().getStatusCode() == 200) {
                // success
                Log.w(LOG_TAG, "XSI channel created succesfully");
                InputStream content = objBwResponse.getEntity().getContent();

                onChannelConnected(gChannelId);
                processMessage(content);
            } else {
                // fail
                Log.w(LOG_TAG, "error in creating channel response: "+objBwResponse+" status code: "+(objBwResponse!=null?objBwResponse.getStatusLine():"response null"));

            }




private void processMessage(InputStream content) {
        String responseXML;
        Document documentXML;
        in = new BufferedInputStream(content);
        StringBuilder stringBuilder = new StringBuilder();
        try {
            int input;
            **while ((input = in.read()) != -1) {**
                stringBuilder.append((char) input);

                if (stringBuilder.indexOf(CHANNEL_EVENT_MESSAGE_END_STRING) != -1) {

      

thank

Amith

+3
http ios objective-c channel


source to share


No one has answered this question yet

Check out similar questions:

1834
HTTP GET with request body
1695
How to use java.net.URLConnection to trigger and process HTTP requests
1417
Transport security blocked HTTP plaintext
1373
How are parameters sent in an HTTP POST request?
1217
HTTP status code for update and delete?
1033
Custom HTTP Headers: Naming Conventions
6
POST request for iphone Json to Django server creates QueryDict in QueryDict
1
how to use JsonArray from queue
1
how to send variable to php from object c
0
IOS - Url format send to server



All Articles
Loading...
X
Show
Funny
Dev
Pics