无效的URI:无效端口指定的URL时,有不止一个冒号 [英] Invalid URI: Invalid port specified when url has more than one colon

查看:3871
本文介绍了无效的URI:无效端口指定的URL时,有不止一个冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dnsdynamic.org指向我在我的家乡举行的个人网站。我家的IP地址将被频繁变更每月一次。 。dnsdynamic.org提供一个Web方法调用更新IP

I am using dnsdynamic.org to point to my personal website hosted at my home. My home ip will be frequently changing once a month. dnsdynamic.org provide a web method call to update ip.

https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1

当我把这个过浏览器,它可以完美运行。当我试图通过C#代码来调用这个它抛出以下异常

When I call this through browser it works perfect. When I try to call this through c# code it throws the following exception.

Invalid URI: Invalid port specified.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Net.WebRequest.Create(String requestUriString)

由于在它看起来像的System.Uri尝试解析我的密码作为整数URL中的冒号。

Since there is a colon in the url it looks like system.uri try to parse my password as integer.

我试过后,.ORG添加端口

I tried adding a port after .org

https://username:password@www.dnsdynamic.org:443

没有运气这一点。

可能有人请点我如何解决这个错误。

could someone please point me how to resolve this error.

我试过不逃避,同时创造URI,仍然没有工作逃避的选择。

I tried with don't escape and escape option while creating uri, still not working.

var ri = new Uri("https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1",true);



编辑:
它看起来像用户名导致了问题。我的用户名是我的电子邮件地址。我的电子邮件地址与* .com结尾。因此,URI是试图解析我的密码。

It looks like the username is causing the problem. My username is my email address. And my email address end with *.com. So uri is trying to parse my password.

仍然没有找到解决这个问题的解决方案。我不能改变我的用户名,因为dnsdyanmic.org使用的电子邮件地址作为用户名。

Still no solution found to overcome this issue. I can't change my username since dnsdyanmic.org use the email address as username.

推荐答案

如果您使用的是的HttpWebRequest 使reqeust,你不应该包括在URI的凭据(如你所知,这是无效)。

If you're using an HttpWebRequest to make the reqeust, you shouldn't include the credentials in the URI (as you can tell, it's invalid).

您应该改为添加凭据到的HttpWebRequest ,并让它处理并使它们通过:

You should instead add the credentials to the HttpWebRequest and let it handle passing them through:

// Only broke this up for readability
var uri = new Uri("https://www.dnsdynamic.org/api/?hostname=techno.ns360.info" + 
                  "&myip=127.0.0.1", true);
var cache = new CredentialCache();
cache.Add(uri, "Basic", new NetworkCredential("username", "password"));

var request = WebRequest.Create(uri);
request.Credentials = cache;

这篇关于无效的URI:无效端口指定的URL时,有不止一个冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆