2009-05-21 3 views
1

Windows의 C++를 통해 웹 서버에 파일을 업로드 할 때 수많은 예제를 발견했습니다.Mac에서 HTTP/HTTPS 및/또는 FTP/FTPS를 통해 파일 업로드

그러나 (내 생각에 나는 Google과 잘 어울린다고 생각합니다.) 이후에 고민 중입니다. Mac에서 같은 결과를 얻을 수있는 예제를 찾으십시오.

누구든지 Mac OS에서 웹 서버에 파일을 업로드하는 방법에 대한 도움을 C++ 또는 객관적인 C를 사용하여 가르쳐 줄 수 있습니까?

HTTP/HTTPS 또는 FTP/FTPS (또는 둘 다)를 통해 전송할 수 있습니다.

감사합니다.

답변

1

connection Kit 당신은 당신은 NSMutableURLRequest이 같은 함께있는 NSURLConnection을 사용하려는 것

3

'libcurl'을 사용할 수 있습니다. 위키 백과에서 this article을 참조하십시오.

1

을 찾고 무엇을 할 수 있습니다

NSMutableURLRequest *theRequest=[[NSMutableURLRequest alloc] init]; 
[theRequest addValue:@"attachment;filename=\"file2.gif\"" forHTTPHeaderField:@"Content-disposition"]; 
[theRequest addValue:@"image/gif" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue:@"binary" forHTTPHeaderField:@"Content-Transfer-Encoding"]; 
[theRequest setHttpBody:myBodyNSDataObject]; 
// create the connection with the request 
// and start loading the data 
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
if (theConnection) { 
    // Create the NSMutableData that will hold 
    // the received data 
    // receivedData is declared as a method instance elsewhere 
    receivedData=[[NSMutableData data] retain]; 
} else { 
    // inform the user that the download could not be made 
} 

수정하거나 수있는 NSMutableURLRequest 방법을 사용하여 설정 헤더 :

- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field 

응답은 서버와 함께 제공됩니다. 응답 본문을 다시 가져 오기 위해 구현할 다른 대리자 메서드에 대해서는 Apple's documentation을 확인할 수 있습니다. 준비를 업로드 할 파일의 내용을 나타내는 NSData 객체가 있어야합니다. FTP를 사용하여 동일하게 작업하는 것은 좀 더 복잡하지만이 방법을 사용하면 파일 본문을 게시 할 수 있습니다. 당신은 당신을 NSData 객체가이 같은 헤더를 설정하도록하는 HTTP 포스트의 몸처럼 설정되어 있는지 확인하는 것이 좋습니다 :

[theRequest addValue:@"attachment;filename=\"file2.gif\"" forHTTPHeaderField:@"Content-disposition"]; 
[theRequest addValue:@"image/gif" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue:@"binary" forHTTPHeaderField:@"Content-Transfer-Encoding"]; 

을 그리고 당신은 몸을 추가해야합니다. 서버 측에서는 파일 이름과 파일을 구성하는 바이트를 가져올 수 있습니다.

이것은 정확히 사용해야하는 코드는 아니지만 진행 방법에 대한 좋은 아이디어를 제공해야합니다.