url 字符串中的斜杠 (c#)
我在字符串变量中写入一个 url:
var path = @"http://46.146.52.139/" + @"TourService/" + TourName + @"/" + TourName + num + ".mp3";
我期待
http://46.146.142.129/TourService/MyTour/MyTour21.mp3
但是我得到了
http:\/\/46.146.142.129\/TourService\/MyTour\/MyTour21.mp3
如何从 URL 中删除反斜杠? 我尝试了不同的变体,但没有成功
完整方法
public string GetAudioPath(string objectname)
{
var num = _databaseConnector.GetNumOfAudio(objectname);
var path = "http://46.146.142.199/" + "TourService/" + TourName + "/" + TourName + num + ".mp3";
return path;
}
这是一个带有界面的网络方法:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string GetAudioPath(string objectname);
我通过在浏览器中键入来调用网络方法
http://46.146.142.129/TourService/TourService.svc/GetAudioPath?objectname=ObjName01
I write into a string variable an url:
var path = @"http://46.146.52.139/" + @"TourService/" + TourName + @"/" + TourName + num + ".mp3";
I'm expecting
http://46.146.142.129/TourService/MyTour/MyTour21.mp3
However I got
http:\/\/46.146.142.129\/TourService\/MyTour\/MyTour21.mp3
How to throw away backward slashes from the URL?
I tried different variants but didn't succeed
Full method
public string GetAudioPath(string objectname)
{
var num = _databaseConnector.GetNumOfAudio(objectname);
var path = "http://46.146.142.199/" + "TourService/" + TourName + "/" + TourName + num + ".mp3";
return path;
}
this is a web method with interface:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string GetAudioPath(string objectname);
I call web method by typing in my browser
http://46.146.142.129/TourService/TourService.svc/GetAudioPath?objectname=ObjName01
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎有效:
It seems to work:
如果将
WebMessageFormat
更改为 Xml,您应该获得包含在 XML 元素中的原始字符串。此外,使用WebMessageBodyStyle.Bare
不会将其包装在基础结构提供的 XML 元素中。If you change your
WebMessageFormat
to Xml, you should get the raw string wrapped in XML elements. Also, usingWebMessageBodyStyle.Bare
won't wrap it in infrastructure-provided XML elements.