IOS 发送 http 请求

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #1337ff}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s3 {font-variant-ligatures: no-common-ligatures; color: #1337ff}span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s5 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s7 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s8 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s9 {font-variant-ligatures: no-common-ligatures; color: #272ad8}

  

   NSURL *storeURL = [NSURL URLWithString:@"http://127.0.0.1:8080/api/v1/accounts/10/notification/push-notification?cloudpId=18&message=rrrrrr&sign=11111"];


//    
//      NSString *host = @"";
//    
//   [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[host]];
//   
    
    
    NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
    
   
    
    [storeRequest setHTTPMethod:@"POST"];
    
    //NSError *error;
    
//    NSDictionary *requestContents = @{
//                                      
//                                      @"receipt-data": @""
//                                      
//                                      };
//    
//    NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
//                           
//                                                          options:0
//                           
//                                                            error:&error];
//    
//    [storeRequest setHTTPBody:requestData];
//    
    
    NSString *bodyData = @"cloudpId=18&message=sssssss&sign=11111111";
    
    [storeRequest setHTTPBody:[NSData dataWithBytes:[bodyData UTF8String] length:strlen([bodyData UTF8String])]];
    
    
    // Make a connection to the iTunes Store on a background queue.
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    
    [NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
     
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                               
                               if (connectionError) {
                                   
                                   /* ... Handle error ... */
                                   
                                   NSLog(@"%@",connectionError);
                                   
                               } else {
                                   
                                   NSError *error;
                                   
                                   NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
                                   
                                   if (!jsonResponse) { /* ... Handle error ...*/ }
                                   
                                   /* ... Send a response back to the device ... */
                                   
                                   NSLog(@"%@",jsonResponse);
                               }
                               
                           }];
    

你可能感兴趣的:(IOS 发送 http 请求)