public static T Post<T>(string url, string data, string staffId, string contentType) { try { byte[] bytes = Encoding.UTF8.GetBytes(data); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); string timeStamp = ApiHelper.GetTimeStamp(); string random = ApiHelper.GetRandom(); httpWebRequest.Headers.Add("staffid", staffId.ToString()); httpWebRequest.Headers.Add("timestamp", timeStamp); httpWebRequest.Headers.Add("nonce", random); //ResultMsg signToken = ApiHelper.GetToken(url, staffId); // httpWebRequest.Headers.Add("signature", ApiHelper.GetSignature(timeStamp, random, staffId, data, signToken)); httpWebRequest.Headers.Add("jwtcookie", GetJwt(url, data));//cwj 直接通过jwt验证身份 httpWebRequest.Method = "POST"; httpWebRequest.ContentLength = (long)bytes.Length; httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"; httpWebRequest.ContentType = contentType; Stream requestStream = httpWebRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); httpWebRequest.Timeout = 300000; httpWebRequest.Headers.Set("Pragma", "no-cache"); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8); string text = streamReader.ReadToEnd(); requestStream.Close(); streamReader.Close(); responseStream.Close(); httpWebRequest.Abort(); httpWebResponse.Close(); return JsonConvert.DeserializeObject<T>(text); } catch (Exception) { throw; } }
时间: 2024-02-14 09:35:07 浏览: 28
这段代码是用于进行 HTTP POST 请求的,其中包括对请求头的设置,请求体的编码和发送,以及响应的解析和反序列化成对象。其中,请求头中包括了 staffid、timestamp、nonce(随机数)和 jwtcookie,这些都是用来验证身份和防止重复请求的。请求体中传入了 data 参数,表示要发送的数据。最后,将响应的文本反序列化成 T 类型的对象并返回。
相关问题
下面是android的图片上传代码,要求上传完后删除图片 private void doSubmitUpload_W() { Map<String, Object> uploadparams = null; try { uploadCallback_w = new AjaxCallback<JSONObject>() { @Override public void callback(String url, JSONObject json, AjaxStatus status) { parseUploadResult_w(url, json,status); } }; Long staffId = SessionManager.getInstance().getStaffId() == null?-1L:SessionManager.getInstance().getStaffId(); uploadparams = new HashMap<String, Object>();// ParamHelper.buildJSONParam(URLs.UPLOADFILE_API,json); String img = preferences.getString("img"+curPhotoPos_W,""); byte[] photots = ImageUtils.Bitmap2Bytes(ImageUtils.getBitmapByPath(img)); uploadparams.put("photoFile2",photots); uploadparams.put("StaffId", staffId); uploadparams.put("StaffName", SessionManager.getInstance().getStaffInfo().getStaffName()); uploadparams.put("OrderID", preferences.getString("isHaveOrder", "")); uploadparams.put("WorkOrderID", preferences.getString("workOrderId","")); uploadparams.put("TypeName", "WORK"); uploadparams.put("photosType", preferences.getString("photosType"+curPhotoPos_W,"")); // 异步网络请求 aQuery.ajax(BaseURLs.UPLOAD_KT_PHOTO, uploadparams, JSONObject.class, uploadCallback_w); } catch (Exception ex) { AlertUtils.showAlert(getBaseContext(), R.string.opt_prompt, R.string.unknown_error); ex.printStackTrace(); upload = false; } }
这段代码是用于在Android平台上实现图片上传功能。在上传完成后,会删除上传的。
代码中的`doSubmitUpload_W()`方法用于执行图片上传操作。首先,创建了一个`AjaxCallback<JSONObject>`对象`uploadCallback_w`,并在其`callback()`方法中调用了`parseUploadResult_w()`方法来解析上传结果。
接下来,获取了当前登录用户的员工ID,并将其放入`uploadparams`参数中。然后,获取了要上传的图片路径,并将图片转换为字节数组放入`uploadparams`参数中。
最后,将其他相关参数(员工姓名、订单ID、工单ID、类型等)放入`uploadparams`参数中,并通过异步网络请求方式调用`BaseURLs.UPLOAD_KT_PHOTO`接口。
注意:这段代码中并未包含删除图片的操作。如果需要在上传完成后删除图片,可以在`parseUploadResult_w()`方法中添加相应的删除逻辑。
select CALL.RULE_ID ruleId, WM_CONCAT(distinct CON.STAFFID) idGroup, SUM(CASE WHEN CALL.CALLSTATUS != '-2' THEN 1 ELSE 0 END) callCount, SUM(CASE WHEN CALL.CALLRESULT = '1' OR CALL.CALLRESULT = '2' THEN 1 ELSE 0 END) resultCount, SUM(CASE WHEN CALL.CALLSTATUS = '-1' THEN 1 ELSE 0 END) waitCallCount, SUM(CASE WHEN CON.CALLBACKSTATUS = '1' THEN 1 ELSE 0 END) addSuccessCount from AC_FIA.TC_CALL_AI CALL LEFT JOIN AC_FIA.TC_WE_CONTACT CON ON CON.RULE_ID = CALL.RULE_ID <where> <if test="query.employeeGroup != null and query.employeeGroup != ''"> AND CALL.RULE_ID = #{query.employeeGroup} </if> </where> group by CALL.RULE_ID,CON.RULE_ID
这是一个 SQL 查询语句,用于从 AC_FIA 数据库的 TC_CALL_AI 和 TC_WE_CONTACT 表中获取数据。查询中包含了规则 ID,员工 ID 组,通话数量,结果数量,等待通话数量和添加成功数量等信息。其中,WM_CONCAT(distinct CON.STAFFID) idGroup 是用于将多个员工 ID 组合为一个字符串。而 <where> 和 <if> 标签则是用于动态生成查询条件的。groupBy 用于对结果进行分组,按照规则 ID 和员工 ID 进行分组。