草庐IT

add_post_condition

全部标签

c# - ASP.NET WebApi Post 方法 - 传递参数时出现 404

我这辈子都弄不明白。我有一个带有Get和Post方法的webapiController。Get方法在有参数和没有参数的情况下都可以正常工作,但是当我尝试向它添加String参数时,帖子中断了。下面是我的代码。路线:config.Routes.MapHttpRoute(name:"DefaultApi",routeTemplate:"{controller}/{id}",defaults:new{id=UrlParameter.Optional});Controller:publicclassAuditController:ApiController{publicStringPost(S

c# - 如何初始化 ConcurrentDictionary?错误 : "Cannot access private method ' Add' here"

我有一个静态类,我在其中使用字典作为查找表以在.NET类型和SQL类型之间进行映射。这是一个这样的字典的例子:privatestaticreadonlyDictionarySqlServerMap=newDictionary{{typeof(Boolean),"bit"},{typeof(Byte[]),"varbinary(max)"},{typeof(Double),"float"},{typeof(Byte),"tinyint"},{typeof(Int16),"smallint"},{typeof(Int32),"int"},{typeof(Int64),"bigint"},{

c# - 无法从 web api POST 读取正文数据

我正在尝试从新的Asp.NetWebApi中的请求中提取一些数据。我有这样的处理程序设置:publicclassMyTestHandler:DelegatingHandler{protectedoverrideSystem.Threading.Tasks.TaskSendAsync(HttpRequestMessagerequest,System.Threading.CancellationTokencancellationToken){if(request.Content.IsFormData()){request.Content.ReadAsStreamAsync().Contin

c# - 为什么 DbSet Add 返回的是实体实例而不是 void?

DbSet.Add方法返回一个实体。我通常会期待Add操作有void返回类型。当我查看EntityFrameworksourcecode,我看到了以下实现:publicvirtualTEntityAdd(TEntityentity){Check.NotNull(entity,"entity");GetInternalSetWithCheck("Add").Add(entity);returnentity;}GetInternalSetWithCheck返回InternalSetAddInternalSet的方法|有趣的是,它的签名中有一个void返回类型:publicvirtualvo

c# - 如何压缩 HttpWebRequest POST

我正在尝试将数据发布到接受压缩数据的服务器。下面的代码工作得很好,但它是未压缩的。我之前没有使用过压缩或Gzip,因此需要任何帮助。HttpWebRequestrequest=WebRequest.Create(uri)asHttpWebRequest;request.Timeout=600000;request.Method=verb;//POSTrequest.Accept="text/xml";if(!string.IsNullOrEmpty(data)){request.ContentType="text/xml";byte[]byteData=UTF8Encoding.UTF

c# - 使用 HttpWebRequest POST 数据/使用 multipart/form-data 上传图像

我正在尝试使用ImageShackAPI上传图片。要使用它,我应该使用multipart/form-dataPOST图像。我这样做了......varpostData="";varreq=HttpWebRequest.Create("http://www.imageshack.us/upload_api.php");req.Method="POST";req.ContentType="multipart/form-data";postData+="key=my_key_here&";postData+="type=base64&";//getbase64datafromimagebyt

c# - 在 c# Parallel.ForEach 中的 List.Add() 上出现 "Index out of bounds"错误

这是代码Listsomething=newList();Parallel.ForEach(anotherList,r=>{..dosomeworksomething.Add(somedata);});Indexoutofbounds错误大约每百次运行1次。有没有办法防止由线程引起的冲突(我假设)? 最佳答案 为了防止出现此问题,您可以使用ConcurrentQueue而不是List或并行部分中的类似并发集合。并行任务完成后,您可以将其放入List中。.有关详细信息,请查看System.Collections.Concurrent命名

c# - 如何将 json 添加到 RestSharp POST 请求

我将以下JSON字符串作为字符串参数传递到我的C#代码中-AddLocation(stringlocationJSON):{"accountId":"57abb4d6aad4","address":{"city":"TEST","country":"TEST","postalCode":"TEST","state":"TEST","street":"TEST"},"alternateEmails":[{"email":"TEST"}],"alternatePhoneNumbers":[{"phoneNumber":"TEST"}],"alternateWebsites":[{"webs

c# - 在 post 请求 asp.net mvc 中更改模型属性

我有一个问题。这是一个简短的例子。这是模型。publicclassMyModel{stringTitle{get;set;}}在我看来我写@Html.TextBoxFor(model=>model.Title)这是Controller。publicActionResultEditNews(intid){varmodel=newMyModel;MyModel.Title="SomeTitle"returnView("News/Edit",model);}//forpost[HttpPost]publicActionResultEditNews(MyModelmodel){//Therei

c# - ApiController Post 中的异步和等待

我对.net4.5中的async和await还不是很清楚。到目前为止,我想我明白await:将函数(在它的右边)放在一个单独的线程上。将执行返回给当前函数的调用者但在等待(异步)函数完成之前保留当前函数的其余代码“人质”。如果我误解了什么,请纠正我。因此,如果上述情况属实,我将无法使用我想要异步的ApiController的Post函数:[HttpPost]publicasyncTaskPost([FromBody]MyObjectobj){myDataContext.MyObjects.InsertOnSubmit(obj);myDataContext.SubmitChanges()