2013-12-17 2 views
1

내가NSMutableURLRequest

"http://localhost/adi/adnan.php" 

에 게시되지 않은 내가 "16 진수 문자열"하지만 데이터를 사용하여 값을 전송하고이 코드 조각을 사용하고 사용하여 데이터를 게시 할 수 없음이 내 코드입니다

 NSLog(@"offset: %i colors: RGB A %i %i %i %i",offset,red,green,blue,alpha); 
     NSString *hexString=[NSString stringWithFormat:@"%02X%02X%02X",red,green,blue]; 
     NSURL *url = [NSURL URLWithString:@"http://localhost/adi/adnan.php"]; 
     NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
     NSString *messageBody = hexString; 
     NSString *msgLength = [NSString stringWithFormat:@"%d", [messageBody length]]; 
     [theRequest setHTTPMethod:@"POST"]; 
     [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
     [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
     [theRequest setHTTPBody:[messageBody dataUsingEncoding:NSUTF8StringEncoding]]; 
     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    if(theConnection) 
        { 
    NSLog(@"Connection Successful"); 
    NSURLResponse *response; 
    NSError *err; 
    NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err]; 
    NSLog(@"responseData here is: %@", responseData); 
    NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    NSLog(@"responseData: %@", str);   
    receivedata=[NSMutableData data]; 
    NSLog(@"data is: %@",receivedata); 
      } 

이 내 PHP 코드

<?php 
    echo "Engr.Adnan; 

// $abc= $_GET['name']; 

    $abc = $_POST['action']; 
    print_r($_REQUEST); 
    echo $adnan = strrev($abc); 

?> 

내가 출력 또는 응답

,617의이 유형을 얻을
2013-12-17 01:33:55.615 VBColorPicker[25216:c07] offset: 27744 colors: RGB A 52 255 36 255 
2013-12-17 01:33:55.650 VBColorPicker[25216:c07] Connection Successful 
2013-12-17 01:33:55.674 VBColorPicker[25216:c07] responseData: <456e6772 2e41646e 616e4172 7261790a 280a290a> 
2013-12-17 01:33:55.675 VBColorPicker[25216:c07] responseData: Engr.AdnanArray 
(
) 
2013-12-17 01:33:55.675 VBColorPicker[25216:c07] data is: <> 

답변

1
당신은 폼 데이터에서 매개 변수 이름을 놓치고

:

NSString *hexString = [NSString stringWithFormat:@"%02X%02X%02X", red, green, blue]; 

그것은

NSString *hexString = [NSString stringWithFormat:@"color=%02X%02X%02X", red, green, blue]; 

하고 다음이

$color = $_POST['color']; 
같은 서버 측을 검색한다

또는 매개 변수 이름을 지정하지 않으려면 전체 매개 변수를 다시 가져올 수 있습니다 퀘스트 본체 서버 쪽 :

$requestBody = file_get_contents('php://input'); // will be the hex string 
+1

답변 해 주셔서 감사합니다. –

관련 문제