我是 iPhone 开发的新手,解码后我从谷歌获得访问令牌,现在我只想检查他/她是否是注册用户。我在 Android 中有代码,我想转换它进入Objective-C。
class HttpHelper
{
private static String token = null;
public static void setToken(String token) {
HttpHelper.token = token;
}
public static String getUrlContentAsString(String url, boolean ignoreHeader)
{
try
{
HttpGet request =new HttpGet(url);
DefaultHttpClient client = new DefaultHttpClient();
if (!ignoreHeader && HttpHelper.token != null)
request.addHeader(new BasicHeader("Authorization",HttpHelper.token));
HttpResponse response = client.execute(request);
HttpEntity responseEntity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
StringBuilder sb = new StringBuilder();
while (true)
{
String line = reader.readLine();
if (line != null)
sb.append(line);
else
break;
}
reader.close();
return sb.toString();
}
catch (Exception e) {
Log.e(
"VerboActivity", e.getMessage());
}
return null;
}
谁能帮我?提前致谢。