public static MiraiShareResult 配車計算の実行_Execute(DateTime dt, ref string msg) { msg = ""; try { 配車計算の実行_Request param = new 配車計算の実行_Request(); param.date = string.Format("{0:yyyy-MM-dd}", dt); Task <MiraiShareResult> r = Task.Run(() => { var json = JsonConvert.SerializeObject(param); var res = GenericPost(miraiShareURL + "sav/batch/demands", json); return(res); }); Task.WaitAll(r); msg = "OK"; return(r.Result);//JsonConvert.DeserializeObject<デマンド登録_Response>(r.Result.receiveJson); } catch (Exception ex) { MiraiShareResult r = new MiraiShareResult(); r.message = msg = ex.Message + ex.StackTrace; r.receiveJson = ""; r.result = ""; r.StatusCode = -1; r.success = false; msg = "ERR"; return(r); } }//1901010001
public static MiraiShareResult 登録したデマンドの削除_Execute(int demandId, ref string msg) { msg = ""; try { 登録したデマンドの削除_Request req = new 登録したデマンドの削除_Request(); req.reasonCode = "finished"; var json = JsonConvert.SerializeObject(req); var res = GenericDelete(miraiShareURL + "sav/demands/" + demandId, json); msg = "OK"; return(res); } catch (Exception ex) { MiraiShareResult r = new MiraiShareResult(); r.message = msg = ex.Message + ex.StackTrace; r.receiveJson = ""; r.result = ""; r.StatusCode = -1; r.success = false; msg = "ERR"; return(r); } }
public static MiraiShareResult GenericDelete(string strUrl, string json) { try { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // httpClient.DefaultRequestHeaders.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); var byteArray = Encoding.ASCII.GetBytes("54300FE5-F441-46E7-BBCA-EEB0C6843FF3:Raiy$oo6Ua+shob4"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl); request.Method = "DELETE"; request.ContentType = "application/json"; request.Accept = "application/json"; request.Headers.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(byteArray); using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); } using (var httpResponse = (HttpWebResponse)request.GetResponse()) { // do something with response var r = new MiraiShareResult(); //r.receiveJson = httpResponse; r.message = "OK"; r.StatusCode = (int)httpResponse.StatusCode; r.success = true; return(r); } } catch (Exception ex) { var r = new MiraiShareResult(); r.receiveJson = ""; r.message = ex.Message + ex.StackTrace; r.StatusCode = -1; r.success = false;; return(r); } }
public async static Task <MiraiShareResult> GenericPut(string strUrl, string json) { try { // POST 先の Uri uri = new Uri(strUrl); //HttpClient を作成しヘッダーを設定します HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // httpClient.DefaultRequestHeaders.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); var byteArray = Encoding.ASCII.GetBytes("54300FE5-F441-46E7-BBCA-EEB0C6843FF3:Raiy$oo6Ua+shob4"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); //contentの確定 StringContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); // データを送信します HttpResponseMessage response = await httpClient.PutAsync(uri, content); //結果を取得 var result = response.Content.ReadAsStringAsync().Result; var r = new MiraiShareResult(); r.receiveJson = result; r.message = "OK"; r.StatusCode = (int)response.StatusCode; r.success = true; return(r); } catch (Exception ex) { var r = new MiraiShareResult(); r.receiveJson = ""; r.message = ex.Message + ex.StackTrace; r.StatusCode = -1; r.success = false;; return(r); } }
public async static Task <MiraiShareResult> GenericPut(string strUrl, string json) { try { // POST 先の Uri uri = new Uri(strUrl); //HttpClient を作成しヘッダーを設定します HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); //contentの確定 StringContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); // データを送信します HttpResponseMessage response = await httpClient.PutAsync(uri, content); //結果を取得 var result = response.Content.ReadAsStringAsync().Result; var r = new MiraiShareResult(); r.receiveJson = result; r.message = "OK"; r.StatusCode = (int)response.StatusCode; r.success = true; return(r); } catch (Exception ex) { var r = new MiraiShareResult(); r.receiveJson = ""; r.message = ex.Message + ex.StackTrace; r.StatusCode = -1; r.success = false;; return(r); } }
public static MiraiShareResult GenericDelete(string strUrl, string json) { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl); request.Method = "DELETE"; request.ContentType = "application/json"; request.Accept = "application/json"; request.Headers.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); } using (var httpResponse = (HttpWebResponse)request.GetResponse()) { // do something with response var r = new MiraiShareResult(); //r.receiveJson = httpResponse; r.message = "OK"; r.StatusCode = (int)httpResponse.StatusCode; r.success = true; return(r); } } catch (Exception ex) { var r = new MiraiShareResult(); r.receiveJson = ""; r.message = ex.Message + ex.StackTrace; r.StatusCode = -1; r.success = false;; return(r); } }
private static async Task <MiraiShareResult> HttpClientSendExecute(HttpMethod type, string fullUrl) { //await aaaa(fullUrl); MiraiShareResult resultMessage = new MiraiShareResult(); resultMessage.StatusCode = -1; resultMessage.message = ""; resultMessage.receiveJson = ""; resultMessage.result = ""; resultMessage.success = false; try { // content - type: application / json //accept: application / json //authorization: Basic RkEyOEVBMDAtNjZEOC00M0IzLThDOTUtRDQ2RUVGQkRBRjYyOmhNMkhZWEd6UjBDMDA4Rw== /*** コード書いてもいい **/ //Httpクライアント var httpClient = new HttpClient(); HttpResponseMessage response; //リクエスト var httpRequest = new HttpRequestMessage(type, fullUrl); if (type == HttpMethod.Post) { FormUrlEncodedContent param = new FormUrlEncodedContent(new Dictionary <string, string> { { "latitude", "35.19078742" }, { "longitude", "137.0487333" }, }); var content = new ByteArrayContent(Encoding.UTF8.GetBytes("")); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(Header1_ContentType_Value); //content.Headers.Add("authorization", "Basic RkEyOEVBMDAtNjZEOC00M0IzLThDOTUtRDQ2RUVGQkRBRjYyOmhNMkhZWEd6UjBDMDA4Rw=="); //httpRequest.Content = new ByteArrayContent(Encoding.UTF8.GetBytes("{}")); //httpRequest.Content.Headers.TryAddWithoutValidation(@"Content-Type", Header1_ContentType_Value); // OK //httpRequest.Headers.Add(Header1_ContentType_ItemName, Header1_ContentType_Value); httpRequest.Headers.Add(Header2_Accept_ItemName, Header2_Accept_Value); httpRequest.Headers.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); httpRequest.Content = content; //response = await httpClient.PostAsync(fullUrl, content); response = await httpClient.SendAsync(httpRequest); } else if (type == HttpMethod.Put) { httpRequest.Headers.Add(Header1_ContentType_ItemName, Header1_ContentType_Value); httpRequest.Headers.Add(Header2_Accept_ItemName, Header2_Accept_Value); httpRequest.Headers.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); } else if (type == HttpMethod.Get) { httpRequest.Headers.Add(Header2_Accept_ItemName, Header2_Accept_Value); httpRequest.Headers.Add(Header3_Authorize_ItemName, Header3_Authorize_Value); } else { resultMessage.message = "method type err:" + type.ToString(); return(resultMessage); } //var response = await httpClient.SendAsync(httpRequest,content ); var r = new MiraiShareResult(); return(r); } catch (Exception ex) { resultMessage.message = "Exception:" + ex.Message + ex.StackTrace; return(resultMessage); } }