我有一个querystrings的get请求,运行正常。但是当我从类型中添加查询字符串时:
public String getSsid()
{
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID();//I add the return value
}
请求请求不适用于此类数据(当我使用getSystemService(TELEPHONY_SERVICE)
时也不起作用)。使用变量,否则它可以工作。
AndroidManifest的权限还可以。
这是我的代码:
public class MenuActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Bundle bundle = this.getIntent().getExtras();
((MyApplication) this.getApplication()).setAppUser(bundle.getString("email"));
String email= ((MyApplication) this.getApplication()).getAppUser();
String ssid = getSsid();
//IF I REMOVE THE SSID AND LEAVE THE EMAIL IT WORKS!!
String mUrl = "http://www.MyUrl.com/app/get.aspx?appId=0001&email=" + email + "&ssid" +ssid;
new HttpAsyncTask().execute(mUrl);
}
private class HttpAsyncTask extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... urls)
{
return GET(urls[0]);
}
}
public static String GET(String url)
{
InputStream inputStream = null;
String result = "";
try
{
// create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// make GET request to the given URL
org.apache.http.HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
}
catch (Exception e)
{
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException
{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
public String getSsid()
{
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID();
}
}
答案 0 :(得分:0)
您提供的错误查询字符串。你错过了一个“等于”的标志。
应该是
String mUrl = "http://www.MyUrl.com/app/get.aspx?appId=0001&email="+ email + "&ssid=" +ssid;