小编Uhe*_*esh的帖子

HTTP在Android模拟器中不起作用

我试过多个HTTP类(HttpURLConnection,HTTPClient和其他人),但他们没有在模拟器上工作.然后我决定在我的手机上进行测试,效果很好!

那么如何修复Android模拟器的这种奇怪的行为,即HTTP类不起作用(浏览器可以工作)?他们崩溃了一个应用程序.

这是我的代码:

public static SimpleXML getResponse(String action, Map<String, String> params) {
     // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(action);

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size());
        for(Map.Entry<String, String> heh : params.entrySet())
            nameValuePairs.add(new BasicNameValuePair(heh.getKey(), heh.getValue()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        return SimpleXML.loadXml(response.getEntity().getContent());       

    } catch (ClientProtocolException e) {
        return null;
    } catch (IOException e) {
        return null; …
Run Code Online (Sandbox Code Playgroud)

android http

11
推荐指数
2
解决办法
1万
查看次数

phpinfo() 什么都不输出

我试过 phpinfo() 但它什么也没输出。有趣的是,php-r "phpinfo();"在 web 中使用 phpinfo() 时可以正常工作,但没有任何输出。同样,error.log 也没有写入任何内容。php.ini是空的。

我现在不知道该怎么办。

编辑:

感谢lanzz,我知道 phpinfo() 在它之前不需要输出。

php apache phpinfo

7
推荐指数
3
解决办法
2万
查看次数

WebClient CookieContainer在.NET 4.0+中运行良好,但在早期版本中运行不佳

我正在开发一个使用WebClient的应用程序.我有这个扩展基本WebClient功能的类:

public class WebClientEx : WebClient
{
    private CookieContainer _cookieContainer = new CookieContainer();

    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest request = base.GetWebRequest(address);
        if (request is HttpWebRequest)
        {
            (request as HttpWebRequest).CookieContainer = _cookieContainer;
            (request as HttpWebRequest).AllowAutoRedirect = true;
            (request as HttpWebRequest).Timeout = 10000;
        }
        return request;
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用WebClientEx登录到站点并请求一些信息.它适用于4.0和4.5,但它不适用于早期版本,如3.5,3.0等.我添加了一些调试代码,在早期版本中,它说cookie容器中有0个cookie,而4.0+表示那里应该是两个饼干.

所以原因可能是早期版本的.NET Framework 在cookie容器中存储cookie时存在一些问题.如何解决?

.net c# webclient

5
推荐指数
2
解决办法
3746
查看次数

如何将应用程序放到后台?

如何将应用程序(活动?)放到后台,以便它可以在那里工作?

moveTaskToBack(true);不起作用.我有android:noHistory="true"和这个代码:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    switch(keyCode)
    {
        case KeyEvent.KEYCODE_BACK:
            moveTaskToBack(true);
            return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

怎么了?如何将应用程序放到后台?

upd:或者我可以只在root(MAIN,LAUNCHER)活动中使用moveTaskToBack(true)?

android background-process

1
推荐指数
1
解决办法
4312
查看次数

标签 统计

android ×2

.net ×1

apache ×1

background-process ×1

c# ×1

http ×1

php ×1

phpinfo ×1

webclient ×1