小编xZe*_*rox的帖子

用于IP到位置API的PHP Regex

我如何使用Regex获取有关IP到Location API的信息

这是API

http://ipinfodb.com/ip_query.php?ip=74.125.45.100

我需要获得国家名称,地区/州和城市.

我试过这个:

$ip = $_SERVER["REMOTE_ADDR"];
$contents = @file_get_contents('http://ipinfodb.com/ip_query.php?ip=' . $ip . '');
$pattern = "/<CountryName>(.*)<CountryName>/";
preg_match($pattern, $contents, $regex);
$regex = !empty($regex[1]) ? $regex[1] : "FAIL";
echo $regex;
Run Code Online (Sandbox Code Playgroud)

当我回复$ regex时,我总是得到失败怎么能解决这个问题

php regex xml api geoip

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

C#如何获得操作系统架构(x86或x64)?

可能重复:
如何使用.net检测Windows 64位平台?

如何使用.NET 2.0检索操作系统体系结构(x86或x64)?

我还没有找到任何在Google上获得操作系统架构的好方法.我发现的是如何判断进程是32位还是64位.

如果无论如何都没有在.NET 2.0中找到,请告诉我.:)

c# windows 64-bit x86 .net-2.0

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

C#WebClient使用Async并返回数据

好吧,我在使用DownloadDataAsync并将字节返回给我时遇到了问题.这是我正在使用的代码:

    private void button1_Click(object sender, EventArgs e)
    {
        byte[] bytes;
        using (WebClient client = new WebClient())
        {
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
            bytes = client.DownloadDataAsync(new Uri("http://example.net/file.exe"));
        }
    }
    void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;
        label1.Text = Math.Round(bytesIn / 1000) + " / " + Math.Round(totalBytes / 1000);

        progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
        if (progressBar1.Value == 100)
        {
            MessageBox.Show("Download Completed");
            button2.Enabled = true;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是"无法将类型'void'隐式转换为'byte []'"

无论如何我可以使这成为可能,并在完成下载后给我字节数?删除"bytes …

c# asynchronous download progress-bar

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

C#从字节运行

我正在努力让我的客户端通过下载字节并使用反射打开它来打开另一个程序.我目前在C#控制台应用程序上工作,但是当我尝试在Windows窗体应用程序上执行此操作时,我收到此错误.

"调用的目标引发了异常."

这是代码

using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
    private void listBox1_DoubleClick(object sender, EventArgs e)
    {
        if (listBox1.SelectedItem.ToString() != null)
        {
            if (MessageBox.Show("Run " + listBox1.SelectedItem.ToString() + "?", "Run this program?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                byte[] bytes;
                using (WebClient client = new WebClient())
                {
                    bytes = client.DownloadData(new Uri("http://example.net/program.exe"));
                }
                RunFromBytes(bytes);
            }
        }
    }
    private static void RunFromBytes(byte[] bytes)
    {
        Assembly exeAssembly = Assembly.Load(bytes);
        exeAssembly.EntryPoint.Invoke(null, null);
    }
Run Code Online (Sandbox Code Playgroud)

.net c# reflection byte assemblies

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

VB.net正则表达到C#

我如何从VB.net将其转换为C#.我尝试了在线转换器但是当我把它放在我的项目中时我遇到了错误.

Dim regexinfo As String = String.Empty
Dim p = "\[news\](?<info>.*?)\[/news\]"
Dim Matches = Regex.Matches(response, p, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
If Matches IsNot Nothing AndAlso Matches.Count > 0 Then
    For Each Match As Match In Matches
        If Match.Groups("info").Success Then
            regexinfo = (Match.Groups("info").Value)
        End If
    Next
End If
Run Code Online (Sandbox Code Playgroud)

c# regex vb.net pattern-matching

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