小编LeC*_*One的帖子

How do you send an HTTP Get Web Request in Python?

我无法将数据发送到网站并在Python中获得响应.我见过类似的问题,但似乎没有一个能达到我的目标.

这是我正在尝试移植到Python的C#代码:

    static void Request(Uri selectedUri)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(selectedUri);
        request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
        request.Method = "GET";
        request.Timeout = (int)Timeout.TotalMilliseconds;
        request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
        request.CachePolicy = CachePolicy;
        request.UserAgent = UserAgent;

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
            {
                string responseText = responseReader.ReadToEnd();
                File.WriteAllText(UrlFileName, responseText.Trim(), Encoding.ASCII);
            }
        }
     }
Run Code Online (Sandbox Code Playgroud)

这是我在Python中的尝试:

def request():
web = httplib.HTTPConnection('https://someurl.com');
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
web.request("GET", "/heartbeat.jsp", headers);
response = web.getresponse();
stream = ""; #something is wrong here
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

python http webrequest streamreader

69
推荐指数
2
解决办法
21万
查看次数

运行C#程序以单声道启动另一个C#程序

我目前运行的是C#编写的服务器软件程序,我试图
增加对Linux上这个.NET软件支持.几乎所有东西都在单声道下工作,但有些东西不起作用.举例来说,在服务器软件的成功关闭,C#编写的另一个外部程序应该立即弹出,从文本文件发送数据的心跳.在.net环境中,例如Windows 7,这很简单

Process.Start("Heartbeat.exe");
Run Code Online (Sandbox Code Playgroud)

就是这样.它弹出来了.

Annnnnnnnd,当服务器软件检测到主机OS运行单,在服务器关机功能,我已经尝试运行其他代码.上面的代码没有效果.我试过这个,但我可能不知道我在做什么.

ProcessStartInfo procInfo = new ProcessStartInfo();
procInfo.UseShellExecute = false;
procInfo.FileName = "Heartbeat.exe";
Process.Start(procInfo);  
Run Code Online (Sandbox Code Playgroud)

这也不起作用.我试图运行一个.sh来运行.exe以及单声道args,但效率非常低.非常感谢任何帮助和所有帮助.(在你们大吼大叫之前,像大多数人一样阅读单声道和ProcessStartInfo API之前,我都读过它们,但我仍然一无所知.单声道API也很奇怪.)

编辑:

谢谢Lex Li的回答,但是在使用时

Process.Start("mono Heartbeat.exe")
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error when getting information for file '/home/me/Desktop/LCDev/mono Heartbeat.exe': No such file or directory
Run Code Online (Sandbox Code Playgroud)

我假设上面的代码试图运行一个名为"mono Heartbeat.exe"的程序,而不是打开带有mono的Heartbeat.exe.

.net c# linux ubuntu mono

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

标签 统计

.net ×1

c# ×1

http ×1

linux ×1

mono ×1

python ×1

streamreader ×1

ubuntu ×1

webrequest ×1