小编jjd*_*v80的帖子

使用HttpURLConnection下载html时的奇怪行为

在我的Android维基百科阅读器应用程序中,我通过使用HttpURLConnection下载文章的html,一些用户报告他们无法看到文章,而是他们看到一些CSS,所以看起来他们的运营商在下载之前以某种方式预处理html ,而其他维基百科读者似乎工作正常.

示例网址:http://en.m.wikipedia.org/wiki/Black_Moon_(album)

我的方法:

public static String downloadString(String url) throws Exception
{
    StringBuilder downloadedHtml = new StringBuilder(); 

    HttpURLConnection urlConnection = null;
    String line = null;
    BufferedReader rd = null;

    try
    {
        URL targetUrl = new URL(url);

        urlConnection = (HttpURLConnection) targetUrl.openConnection();

        if (url.toLowerCase().contains("/special"))
            urlConnection.setInstanceFollowRedirects(true);
        else
            urlConnection.setInstanceFollowRedirects(false);

        //read the result from the server
        rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

        while ((line = rd.readLine()) != null)
            downloadedHtml.append(line + '\n');
    }
    catch (Exception e)
    {
        AppLog.e("An exception occurred while downloading data.\r\n: " …
Run Code Online (Sandbox Code Playgroud)

java android http httpurlconnection

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

Windows Phone 8上的X509Certificate2到X509Certificate

我需要在WP8上制作以下代码,问题是WP8上没有X509Certificate2类,我尝试过使用充气城堡api,但我还没有真正弄明白.

有没有办法让这个代码在WP8上运行?

    private string InitAuth(X509Certificate2 certificate, string systemId, string username, string password)
    { 
        byte[] plainBytes = Encoding.UTF8.GetBytes(password);
        var cipherB64 = string.Empty;
        using (var rsa = (RSACryptoServiceProvider)certificate.PublicKey.Key)
            cipherB64 = systemId + "^" + username + "^" + Convert.ToBase64String(rsa.Encrypt(plainBytes, true));

        return cipherB64;
    }
Run Code Online (Sandbox Code Playgroud)

c# encryption windows-phone-7 windows-phone windows-phone-8

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

获取AppDomain中所有可用命名空间的列表

我需要在运行时"扫描"所有已加载程序集的活动AppDomain,并获取这些程序集中可用的唯一名称空间列表,.NET支持吗?

代码必须在运行时执行,以便代码是动态的.

我刚开始使用C#进行编码,所以我不确定从哪里开始,所以任何帮助都将受到赞赏.

c# dynamic appdomain .net-assembly

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

以编程方式从.NET中的WikiPedia获取文章

我需要以编程方式从维基百科中获取文章,我需要能够以HTML或原始文本的形式获取部分及其内容.

以此页为例:http://en.m.wikipedia.org/wiki/LINQ

我发现这个.NET Api,但它似乎不支持获取文章.

https://github.com/svick/LINQ-to-Wiki

我可以使用任何.NET库,还是必须解析网站的html内容?

PS我知道维基百科有一个API,但我看不到任何如何用它来做我需要的例子.

c# wikipedia wikimedia linq-to-wiki

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

C#位运算符

有人可以解释以下代码的作用.

private int ReadInt32(byte[] _il, ref int position)
{
    return (((il[position++] | (il[position++] << 8)) | (il[position++] << 0x10)) | (il[position++] << 0x18));
}
Run Code Online (Sandbox Code Playgroud)

我不确定我理解这种方法中的按位运算符是如何工作的,有些人可以帮我分解一下吗?

c# bit-manipulation

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