我只是按照同步模式调用HttpClient的示例,它在Console应用程序中正常工作.
但是,当我将它移动到wpf应用程序时,程序挂起而没有任何返回.
我尝试通过构建一个单独的类来处理访问www.google.com的虚拟请求来隔离问题.
似乎应用程序在调用client.GetAsync时挂起,我可以知道在这种情况下是否有任何东西需要从控制台应用程序更改为wpf?
请找到控制台应用程序和wpf的来源,如下所示,
控制台应用 - 工作正常:
using System;
using System.Threading.Tasks;
using System.Net.Http;
namespace ca03
{
static class action
{
static async Task<string> DownloadPageAsync()
{
// ... Target page.
string page = "http://www.google.com/";
// ... Use HttpClient.
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(page))
using (HttpContent content = response.Content)
{
// ... Read the string.
string result = await content.ReadAsStringAsync();
// ... Display the result.
if (result != null &&
result.Length >= 50)
{ …Run Code Online (Sandbox Code Playgroud) 更新中...
抱歉实时调试.我整天都陷入困境,我想写出来让我更接近研究它......
我注意到我正在使用setUseEPSVwithIPv4(true)发送一个
EPSV
229 Entering Passive Mode (|||62110|)
Run Code Online (Sandbox Code Playgroud)
删除它让我更进一步,现在我得到了
Total Bytes To Send: 1033
PASV
227 Entering Passive Mode (xxx,xxx,xxx,42,242,189)
STOR /Inbound/Encrypted/TEST.pgp
File Transfer Failed at: 2013-11-21 18:33:07.846
Error Occurred Transmitting File to Remote System, aborting...
Host attempting data connection xxx.xxx.xxx.42 is not same as server xxx.xxx.xxx.67
java.io.IOException: Host attempting data connection xxx.xxx.92.42 is not same as server xxx.xxx.xxx.67
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:912)
at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:600)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:633)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624)150 Opening ASCII mode SSL data connection for /Inbound/Encrypted/TCONW.TEST.IN.pgp.
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976)
at mycode.FTPConnection.sendFile(FTPConnection.java:667) …Run Code Online (Sandbox Code Playgroud)