1
我正在使用ASIFormDataRequest將圖片上傳到TwitPic,並且我得到了一個響應,從這裏一切正常。但在- (void)requestFinished:(ASIHTTPRequest *)request
我已經有一個TwitLonger響應的動作(正常工作)。現在,我將如何根據響應類型來執行不同的操作?我嘗試設置一個字符串並與if
進行比較,得到響應的最後一個東西,但沒有運氣。這是我試過的方式:如何根據ASIHTTPRequest執行不同的操作?
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
NSString *first = [responseString substringFromIndex: [responseString length] - 7];
NSLog(@"%@", first);
if (first == @"</rsp>"+
) {
NSString *responseString = [request responseString];
NSLog(@"%@", responseString);
NSString *result = nil;
// Determine "<div>" location
NSRange divRange = [responseString rangeOfString:@"<mediaurl>" options:NSCaseInsensitiveSearch];
if (divRange.location != NSNotFound)
{
// Determine "</div>" location according to "<div>" location
NSRange endDivRange;
endDivRange.location = divRange.length + divRange.location;
endDivRange.length = [responseString length] - endDivRange.location;
endDivRange = [responseString rangeOfString:@"</mediaurl>" options:NSCaseInsensitiveSearch range:endDivRange];
if (endDivRange.location != NSNotFound)
{
// Tags found: retrieve string between them
divRange.location += divRange.length;
divRange.length = endDivRange.location - divRange.location;
result = [responseString substringWithRange:divRange];
}
tweet.text = result;
NSLog(@"%@", result);
}
} else {
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(@"%@", responseString);
NSString *result = nil;
// Determine "<div>" location
NSRange divRange = [responseString rangeOfString:@"<content>" options:NSCaseInsensitiveSearch];
if (divRange.location != NSNotFound)
{
// Determine "</div>" location according to "<div>" location
NSRange endDivRange;
endDivRange.location = divRange.length + divRange.location;
endDivRange.length = [responseString length] - endDivRange.location;
endDivRange = [responseString rangeOfString:@"</content>" options:NSCaseInsensitiveSearch range:endDivRange];
if (endDivRange.location != NSNotFound)
{
// Tags found: retrieve string between them
divRange.location += divRange.length;
divRange.length = endDivRange.location - divRange.location;
result = [responseString substringWithRange:divRange];
}
tweet.text = result;
[_engine setAccessToken:token];
[_engine sendUpdate:tweet.text];
[self.parentViewController dismissModalViewControllerAnimated:true];
}
}
}
這是響應的一個例子:
<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<mediaid>50ia96</mediaid>
<mediaurl>URL GOES HERE</mediaurl>
</rsp>
這樣結束了,我想越來越標籤之間的URL的內容。
在此先感謝!
感謝您的聯繫!我認爲第一個選項(用戶信息一)似乎是正確的,但我該怎麼做呢?謝謝:) – pmerino 2011-05-21 13:07:15
檢查我編輯的答案 – phi 2011-05-21 13:16:21
非常感謝!它的工作:D – pmerino 2011-05-21 13:19:13