我想制作一个传递4个参数的web api.
这是我的路线:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{email}/{firstname}/{lastname}/{source}"
);
Run Code Online (Sandbox Code Playgroud)
这是方法签名
public string GetId(string email, string firstname, string lastname, string source)
Run Code Online (Sandbox Code Playgroud)
这是调用网址
http://fakedomain.com/api/Contacts/GetId?email=user@domain.com&firstname=joe&lastname=shmoe&source=123
Run Code Online (Sandbox Code Playgroud)
我收到404错误.
如果我在路由配置中将每个参数设置为可选,并使用默认值设置每个参数,则会调用它.但是,每个参数都获取默认值,而不是传递的值.
我觉得我很亲近,我错过了什么?
我正在扩展网络ApiController服务.
该服务将GUID作为其唯一参数.这是我输入的网址
/api/texts/2ADEA345-7F7A-4313-87AE-F05E8B2DE678
Run Code Online (Sandbox Code Playgroud)
然而,Guid永远不会达到这个Get方法.
如果我将它设置为对象
public Object Get(Object userId)
Run Code Online (Sandbox Code Playgroud)
触发该方法,但userid为null.
如果我把它设置为guid
public Object Get(Guid? userId)
Run Code Online (Sandbox Code Playgroud)
我收到了错误
在与请求匹配的控制器"文本"上未找到任何操作.
有没有人有可以帮助我的样品?
我有一个项目,我需要通过Web请求发送数据文件.我们需要设置双向身份验证,也称为相互身份验证.我们不确定是否需要特殊证书,但我们知道它需要达到3级.
我在查找此案例的示例代码时遇到问题.我不知道在哪里添加我们的证书信息.使用此代码Underlying connection is closed时,当我们尝试读取响应流并且ServicePointManager.ServerCertificateValidationCallback从未调用时会抛出错误.这是我有的:
ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf MyCertValidationCb)
httpReq = CType(System.Net.HttpWebRequest.Create(url), HttpWebRequest)
For Each cert As String In certs
X509cert = X509Certificate2.CreateFromCertFile(cert)
X509cert2 = New X509Certificate2(X509cert)
httpReq.ClientCertificates.Add(X509cert2)
Next
httpReq.Method = "POST" ' Post method
httpReq.ContentType = "text/xml" ' content type
' Wrap the request stream with a text-based writer
writer = New StreamWriter(httpReq.GetRequestStream())
' Write the XML text into the stream
reader = New StreamReader(filename.Name)
ret = reader.ReadToEnd()
reader.Close()
' Send the data to …Run Code Online (Sandbox Code Playgroud)