/// <summary> /// 发送请求 /// </summary> public void DoService() { if (string.IsNullOrEmpty(this.apiKey)) { this.haveDoneService = true; this.ocrResult = "Error:ApiKey 不能为空 "; return; } this.formData["apiKey"] = this.apiKey; this.formData["service"] = this.service.ToString(); this.formData["language"] = this.Language.ToString().ToLower(); if (this.language == Language.Eng) { this.formData["charset"] = ((int)this.charset).ToString(CultureInfo.InvariantCulture); } if (string.IsNullOrEmpty(this.filePath) && string.IsNullOrEmpty(this.fileUrl)) { this.haveDoneService = true; this.ocrResult = "Error:filePath 和 fileUrl 不能同时为空 "; return; } if (!string.IsNullOrEmpty(this.filePath) && File.Exists(this.filePath)) { if (string.IsNullOrEmpty(this.type)) { this.haveDoneService = true; this.ocrResult = "Error:上传识别验证码时 type 必须传图片的原始url "; return; } if (!this.type.StartsWith("http") && !this.type.StartsWith("ftp")) { this.haveDoneService = true; this.ocrResult = "Error:type 必须以 http/https/ftp 开头 "; return; } this.formData["type"] = this.type; this.response = MultiPart.MultiPost(this.apiUrl, this.formData, this.filePath); } else { if (string.IsNullOrEmpty(this.fileUrl)) { this.haveDoneService = true; this.ocrResult = "Error:filePath 和 fileUrl 不能同时为空 "; return; } this.formData["url"] = this.fileUrl; this.response = MultiPart.MultiPost(this.apiUrl, this.formData); } // 检查服务器响应状态 if (this.response.OK) { this.processStatus = true; this.ocrResult = this.response.Response; } else { this.ocrResult = string.Format("Error: {0}", this.response.StatusCode); } this.haveDoneService = true; }
/// <summary> /// Initializes a new instance of the <see cref="CallResponse"/> class. /// </summary> /// <param name="ret"> /// The ret. /// </param> public CallResponse(CallResponse ret) { this.StatusCode = ret.StatusCode; this.Exception = ret.Exception; this.Response = ret.Response; }