'C# RestSharp API can't Post JSON Body but not show any error
I have some issue
I'm Posting my json body via RestSharp c#, author by Token and method is Post! There're nothing Posted to API but My code is not show any error. When I'm Using Postman to Test my Json body, it's working normally. Please give me some idea! Thanks a lot!
This is my C# Code:
var client = new RestClient("https://apis.haravan.com/com/orders.json");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
client.Timeout = -1;
request.AddHeader("Authorization", "Bearer " + "720105BE68AB1429E4887AB4AFC334BEA21E55A6EDA454A4663884CD6B241524");
string text = "{'order':{'shipping_address':{'address1':'12A, Quận 5','country':'Vietnam','first_name':'B','id':1101553305,'last_name':'Nguyễn Thị','phone':'01234567890','province':'Hồ Chí Minh','zip':'70000','name':'Nguyễn Thị B','province_code':'HC','country_code':'vn','default':true,'district':'Quận 5','district_code':'HC470','ward':'Phường 13','ward_code':'27343'},'billing_address':{'address1':'12A, Quận 5','country':'Vietnam','first_name':'B','id':1101553305,'last_name':'Nguyễn Thị','phone':'01234567890','province':'Hồ Chí Minh','zip':'70000','name':'Nguyễn Thị B','province_code':'HC','country_code':'vn','default':true,'district':'Quận 5','district_code':'HC470','ward':'Phường 13','ward_code':'27343'},'fulfillment_status':'fulfilled','line_items':[{'grams':150,'id':1425090843,'price':444000,'price_original':444000,'price_promotion':0,'product_id':1021445372,'quantity':1,'requires_shipping':true,'sku':'F-201WA-9ADF','title':'F-201WA-9ADF','variant_id':1043345992,'variant_title':'Default Title','vendor':'CASIO','type':'ĐỒNG HỒ','name':'F-201WA-9ADF - Default Title','gift_card':false,'taxable':true,'tax_lines':null,'product_exists':true,'barcode':null,'properties':null,'applied_discounts':[],'total_discount':0,'image':{'src':'https://product.hstatic.net/1000388227/product/f-201wa-9adf_65c56f94b53840f9aa1f848f83156074.png'},'not_allow_promotion':false,'ma_cost_amount':0,'actual_price':0},{'grams':130,'id':1429944636,'price':4343000,'price_original':4343000,'price_promotion':0,'product_id':1038042955,'quantity':1,'requires_shipping':true,'sku':'BA-130SP-7ADR','title':'BA-130SP-7ADR','variant_id':1083244078,'variant_title':'Default Title','vendor':'CASIO','type':'ĐỒNG HỒ','name':'BA-130SP-7ADR - Default Title','gift_card':false,'taxable':true,'tax_lines':null,'product_exists':true,'barcode':'BA-130SP-7ADR','properties':null,'applied_discounts':[],'total_discount':0,'image':{'src':'https://product.hstatic.net/1000388227/product/ba-130sp-7adr_7f5aaf661f4845d08b779a1a22de0f2d.jpg'},'not_allow_promotion':false,'ma_cost_amount':0,'actual_price':0}],'confirmed_at':'2022-05-07T03:50:01.194Z','confirmed_status':'confirmed','financial_status':'paid','source_name':'tiki','shipping_lines':[{'code':null,'price':0,'source':null,'title':null}],'fulfillments':[{'created_at':'2022-05-07T03:38:32.251Z','id':1090995371,'order_id':1296326996,'receipt':null,'status':'success','tracking_company':null,'tracking_company_code':null,'tracking_numbers':[],'tracking_number':null,'tracking_url':null,'tracking_urls':[],'updated_at':'2022-05-07T03:38:32.273Z','line_items':[{'fulfillable_quantity':0,'fulfillment_service':'Thủ công','fulfillment_status':'Đã hoàn thành','grams':150,'id':1430378337,'price':444000,'product_id':null,'quantity':1,'requires_shipping':true,'sku':'F-201WA-9ADF','title':'F-201WA-9ADF','variant_id':null,'variant_title':'Default Title','vendor':'CASIO','name':'F-201WA-9ADF','variant_inventory_management':null,'properties':null,'product_exists':false},{'fulfillable_quantity':0,'fulfillment_service':'Thủ công','fulfillment_status':'Đã hoàn thành','grams':130,'id':1430378338,'price':4343000,'product_id':null,'quantity':1,'requires_shipping':true,'sku':'BA-130SP-7ADR','title':'BA-130SP-7ADR','variant_id':null,'variant_title':'Default Title','vendor':'CASIO','name':'BA-130SP-7ADR','variant_inventory_management':null,'properties':null,'product_exists':false}],'province':null,'province_code':null,'district':null,'district_code':'HC470','ward':null,'ward_code':null,'cod_amount':0,'carrier_status_name':'Đã giao hàng','carrier_cod_status_name':'Không','carrier_status_code':'delivered','carrier_cod_status_code':'none','location_id':1287919,'location_name':'Địa điểm mặc định','note':null,'carrier_service_package_name':null,'coupon_code':null,'ready_to_pick_date':null,'picking_date':null,'delivering_date':null,'delivered_date':null,'return_date':null,'not_meet_customer_date':null,'waiting_for_return_date':null,'cod_paid_date':null,'cod_receipt_date':null,'cod_pending_date':null,'cod_not_receipt_date':null,'cancel_date':null,'is_view_before':null,'country':null,'country_code':null,'zip_code':null,'city':null,'real_shipping_fee':0,'shipping_notes':null,'total_weight':0,'package_length':0,'package_width':0,'package_height':0,'boxme_servicecode':null,'transport_type':0,'address':null,'sender_phone':null,'sender_name':null,'carrier_service_code':null,'from_longtitude':0,'from_latitude':0,'to_longtitude':0,'to_latitude':0,'sort_code':null,'is_drop_off':false,'is_insurance':false,'insurance_price':0,'is_open_box':false,'request_id':null,'carrier_options':null,'note_attributes':null,'first_name':'B','last_name':'Nguyễn Thị','shipping_address':'12A, Quận 5','shipping_phone':'01234567890'}],'order_processing_status':'complete','transactions':[]}}";
dynamic body = JsonConvert.DeserializeObject(text);
request.AddParameter("application/json", body, ParameterType.RequestBody);
var response = client.Execute(request).Content;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
