我需要完全URL编码电子邮件地址.
HttpUtility.UrlEncode似乎忽略了某些字符,如!和.
我需要在这样的网址中传递一个电子邮件地址:
/Users/me@example.com/Comments
Run Code Online (Sandbox Code Playgroud)
因为我的WebMethod uri模板如下所示:
[WebGet(UriTemplate = "Users/{emailAddress}/Comments")]
Run Code Online (Sandbox Code Playgroud)
句点会中断WCF,并且不会将电子邮件地址传递给我的REST Web服务方法.删除期间传递的值就好了.我希望有一种方法可以编码所有非字母数字字符,因为消费此服务的所有内容都需要这样做.
编辑
我考虑过使用:
Convert.ToBase64String(Encoding.ASCII.GetBytes("something+me@example.com"))
Run Code Online (Sandbox Code Playgroud)
大多数其他语言有简单的方法将字符串转换为base64吗?我主要担心的是,使用此服务的客户需要使用Java,PHP,Ruby等对电子邮件地址进行编码.
我在视图中有以下代码:
<%= Html.ActionLink(
"View item",
"Index",
"Items",
new
{
itemName = Model.ItemName
},
null) %>
Run Code Online (Sandbox Code Playgroud)
项目名称包含锐利(#)或百分号(%)时出现问题.
当项目名称为时"name#with#sharp#",控制器仅接收名称的第一部分,直到第一个锐利(仅接收"name").
当项目名称是"name%with%percent"我收到错误:HTTP错误400 - 错误的请求.
我不确定这是否是URL编码的问题,因为它适用于其他冲突字符,例如:
;
=
+
,
~
[blank]
Run Code Online (Sandbox Code Playgroud)
你知道我怎么能解决这个问题?
提前致谢.
我正在构建一个包含各种图像标记的SVG文档.图像的xlink:href(源URL)属性包含带有&符号的查询字符串.如果我将它们作为%26或ascii编码? 它们不是有效的查询字符串,服务器也不会传递图像.我无法用CDATA逃避它们,因为它们是属性(不是节点).我已经尝试在图像标记中创建一个xlink:href节点,但是SVG解析器会忽略它.我想使用纯SVG(而不是HTML中的SVG),以便我可以在以后转换为JPG,因此编写脚本...
关于我如何能够完成以下工作的任何提示?
<image x="0" y="0" width="306" height="306" xlink:href="http://host.com/image.jpg?token=asdf&expiration=9384029&etc=etc"/>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在生成一些HTML,我想生成一个XSS和数据库内容安全的mailto链接.这里使用的编码是什么?这个怎么样?
myLiteral.Text = string.Format(
"mailto:{0}?Content-Type=text/html&Subject={1}&body={2}",
HttpUtility.UrlEncode(email_address),
HttpUtility.UrlEncode(subject),
HttpUtility.UrlEncode(body_message));
Run Code Online (Sandbox Code Playgroud)
我应该UrlEncode在这里使用吗? HtmlEncode?做我做的,然后HtmlEncode整个?我正在写一个URL的HTML,所以我有点不清楚......
@Quentin,这就是你所描述的吗?(改变&s到&,因为我要HtmlEncode...)
myLiteral.Text =
HttpUtility.HtmlEncode(HttpUtility.UrlEncode(
string.Format(
"mailto:{0}?Content-Type=text/html&Subject={1}&body={2}",
email_address, subject, body_message)));
Run Code Online (Sandbox Code Playgroud) 在最近的一个项目中,我有幸排除了一个错误,该错误涉及当文件名中有空格时图片无法加载.我想"这是一个简单的问题,我会的UrlEncode()!" 但是,NAY!简单地使用UrlEncode()没有解决问题.
新的问题是HttpUtilities.UrlEncode()方法交换空间() to plusses (+)代替的%20,如浏览器通缉.因此,file+image+name.jpg如果file%20image%20name.jpg发现正确,将返回not-found .
值得庆幸的是,一位同事HttpUtilities.UrlPathEncode()向我指出哪种用途%20代替空间+.
为什么有两种处理Url编码的方法?为什么有两个命令行为如此不同?
我们有一个像http://site.s3.amazonaws.com/images/some image @name.jpg里面的网址$string
我正在尝试做什么(是的,网址周围有一个空格):
$string = urlencode(trim($string));
$string_data = file_get_contents($string);
Run Code Online (Sandbox Code Playgroud)
我得到了什么(@也被替换):
file_get_contents(http%3A%2F%2Fsite.s3.amazonaws.com%2Fimages%2Fsome+image+@name.jpg)[function.file-get-contents]: failed to open stream: No such file or directory
如果您复制/粘贴http://site.s3.amazonaws.com/images/some image @name.jpg到浏览器地址栏中,图像将会打开.
有什么不好以及如何解决这个问题?
我正在努力实施Oauth Api,并且发现有一些我无法验证的事情,如果有人能提供澄清,我会很高兴.警告我可能会絮絮叨叨,所以我会尝试用粗体标记我的问题.
根据oauth 1.0规范http://tools.ietf.org/html/rfc5849,我认为oauth params对签名进行百分比编码的方式与在线时不同.第3.6节http://tools.ietf.org/html/rfc5849#section-3.6 "它仅用于构造签名基本字符串和"授权"头字段."
RFC3986 http://tools.ietf.org/html/rfc3986 这似乎是正常请求中使用的百分比编码方案.但是我没有看到它将任何类型的'this'映射给'that'所以我假设如果字符在保留列表中,则应使用十六进制等效.
签名编码时''(空格)是%20的唯一区别是什么?Oauth规范参考了这一点,但我不能老实地找到其他规范中定义的位置.如果有人能指出我提到的地方以及我可能误解了它,那将是非常棒的.
其他空白字符应该是%20吗?在规范中哪里提到了那个?
传统的UrlEncode是否适用于表单体和查询参数?
最后,我有一些示例输出,我希望验证.我试图显示Oauth Signature Encoded字符和Url编码字符之间的区别.再一次,唯一的区别似乎是'','*'和'〜'的处理
Char Oauth Url
* %2A *
~ ~ %7E
% %25 %25
! %21 %21
: %3A %3A
/ %2F %2F
= %3D %3D
& %26 %26
+ %2B %2B
%20 +
, %2C %2C
@ %40 %40
\r\n %0D%0A %0D%0A
\n %0A %0A
\r %0D %0D
" %22 %22
? %3F %3F
( %28 %28
) %29 %29
| %7C …Run Code Online (Sandbox Code Playgroud) 我有一个简单的ApiController
public HttpResponseMessage Put(int orderid, [FromBody] Order order)
{
// Do something useful with order.Notes here
}
Run Code Online (Sandbox Code Playgroud)
和一个类(实际的类包含更多属性)
public class Order
{
public string Notes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并希望处理以下类型的PUT请求
PUT http://localhost/api/orders/{orderid}
Content-Type: application/x-www-form-urlencoded
notes=sometext
Run Code Online (Sandbox Code Playgroud)
一切正常,但空值传递为null
notes=blah // passes blah
notes= // Passes null
someothervalue=blah // Passes null
Run Code Online (Sandbox Code Playgroud)
是否可以让ApiController区分空值和缺失值?
在我们的Angular应用程序中,我们必须处理包含"点"的id.例如:
book = {
id: '123.456'
}
Run Code Online (Sandbox Code Playgroud)
我们在使用这样的id作为url参数时遇到了问题.如果通过"Angular"进行导航,即点击调用的链接,一切运行良好$state.go('bookDetails', {bookId: book.id});.但重新加载页面时,事情不起作用
"无法获取/bookDetails?bookId=123.456"
在控制器中:
$scope.viewBookDetails = function() {
$state.go('bookDetails', {bookId: book.id});
}
Run Code Online (Sandbox Code Playgroud)
在视图中
<a href="" ng-click="viewBookDetails(); $event.stopPropagation();">
Run Code Online (Sandbox Code Playgroud)
在路由器中:
.state('bookDetails', {
url: '/bookDetails?bookId'
}
Run Code Online (Sandbox Code Playgroud)
在浏览器中:
https://example.com/bookDetails?bookId=123.456
Run Code Online (Sandbox Code Playgroud)
如果%2E在浏览器中替换"点",则链接有效.
我们试图在$ state.go()的参数中用"%2E"替换"dot"
$scope.viewBookDetails = function() {
$state.go('bookDetails', {bookId: book.id.split('.').join('%2E')});
}
Run Code Online (Sandbox Code Playgroud)
但不起作用,因为"%"自动编码,浏览器中的"点"替换为"%252E"
https://example.com/bookDetails?bookId=123%252E456
Run Code Online (Sandbox Code Playgroud) 我一直在尝试/使用以下命令从powershell 访问带有字符的URL (它是对gitlab服务器的查询以检索调用的项目"foo/bar"):
Invoke-WebRequest https://server.com/api/v3/projects/foo%2Fbar -Verbose
Run Code Online (Sandbox Code Playgroud)
现在,奇怪的是使用PowerShell ISE或Visual Studio,请求是正常的.使用PowerShell本身时,URL会自动取消转义,并且请求失败.例如
在ISE/VS中:
$> Invoke-WebRequest https://server.com/api/v3/projects/foo%2Fbar -Verbose
VERBOSE: GET https://server.com/api/v3/projects/foo%2Fbar with 0-byte payload
VERBOSE: received 19903-byte response of content type application/json
StatusCode : 200
StatusDescription : OK
Content : .... data ....
Run Code Online (Sandbox Code Playgroud)
在Powershell中:
$> Invoke-WebRequest https://server.com/api/v3/projects/foo%2Fbar -Verbose
VERBOSE: GET https://server.com/api/v3/projects/foo/bar with 0-byte payload
Invoke-WebRequest : {"error":"404 Not Found"}
At line:1 char:1
+ Invoke-WebRequest 'https://server.com/api/v3/projects/foo%2Fbar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Run Code Online (Sandbox Code Playgroud)
我尝试在URL周围添加单引号和双引号,但没有任何帮助. …
urlencode ×10
asp.net ×3
.net ×2
url ×2
ampersand ×1
angularjs ×1
asp.net-mvc ×1
c# ×1
encode ×1
file ×1
html ×1
mailto ×1
oauth ×1
php ×1
powershell ×1
query-string ×1
svg ×1
url-encoding ×1
wcf ×1
web-services ×1
webrequest ×1
xlink ×1
xss ×1