Previously there was a callback URL for the seven-ox upload image (previously used by the. net4.0, which works)
The code is as follows:
//Seven Ox callback address, callbackbody content Name=upload/member/1.jpg&hash=fn6qeqi4vdlq347nirm-rlqx_4o2 Public ObjectPost ([Frombody]Dynamicdata) {ILog Logger=Logmanager.getlogger (System.Reflection.MethodBase.GetCurrentMethod (). DeclaringType); Logger. Info ("Data:"+data. ToString ()); intStatus =-1; Try { stringAvator_url =Data.name; intStartpos ="upload/member/". Length; stringmember_id = Avator_url. Substring (Startpos, Avator_url. IndexOf (". jpg") -startpos); Memberhelper.updateavator (member_id, Avator_url); varJSON =New{results =New string[0], status =0 }; returnJSON; } Catch(Exception ex) {stringmsg = ex. Message +Ex. StackTrace; Logger. Error ("\ r \ n Data:"+ data. ToString () +"\r\nexception:"+msg, ex); varJSON =New{results =New string[0], status = status, MSG =msg}; returnJSON; } }
The same code now prompts HTTP 415 error in. NET Core – Unsupported media type (Unsupported media types)
Please refer to this article: https://www.cnblogs.com/CreateMyself/p/6246977.html
It is mentioned in the net Mvc/webapi that the Controller has the ability to bind the HTTP request body either as a form post or as a JSON, and the data is returned to us, and we do not need to make any special representations.
seven the URL format of the ox callback should be in Form post (contentType: "application/x-www-form-urlencoded").
The. NET core MVC model bindings, the default parameter binding type is Fromform
Fromquery, corresponding to the urlencoded string ("? key1=value1&key2=value2") in the URL. Fromform, corresponding to the urlencoded string ("Key1=value1&key2=value2") in the request content. Frombody, corresponding to the JSON string in the request content ("{" Key1 ":" Value1 "," Key2 ":" Value2 "}").
. NET Core is strictly limited, Post ([frombody]dynamic data) This notation, must correspond to the parameter type is the JSON format (contentType: "Application/json"), otherwise there will be a 415 error /c0>
All we can do is write 2 methods, no matter how the seven cows use that method to call, can return correctly.
Seven Bull callback address, callbackbody content name=upload/member/memberid.jpg&hash=FN6QEQI4VDLQ347NIRM-RLQX_4O2 [allowanonymous] [HttpPost ("Updateavatorjson")] public object Post ([Fro Mbody]dynamic data) {int status =-1; try {updateavator (data.name); var json = new {results = "", status = 0}; return JSON; } catch (Exception ex) {string msg = ex. Message + ex. StackTrace; var json = new {results = "", Status = status, MSG = MSG}; return JSON; }} [AllowAnonymous] [HttpPost ("Updateavatorform")] public object Post (string name, string have h) {int status =-1; try {updateavator (name); var json = new {results = "", status = 0}; return JSON; } catch (Exception ex) {string msg = ex. Message + ex. StackTrace; var json = new {results = "", Status = status, MSG = MSG}; return JSON; } }
NET core model bindings are different from previous versions