首页 > 解决方案 > Katalon Studio - 无法发送测试请求:开始或结束无效

问题描述

我正在尝试将“POST”网络请求发送到特定地址(例如:https ://qa.alycedev.com/ )

发送我的网络请求时,任何属性集(标题、正文、cookie、url 编码/解码)都会导致错误:

警告 > 无法发送测试请求。原因:java.lang.IllegalArgumentException:无效的开始或结束。

您可以在下面找到错误的详细信息: https ://i.stack.imgur.com/szGan.png

我的请求示例:

@Keyword
def purchase_simple (def totalCookies) {
    WebUI.comment('Total number of cookies=' +totalCookies.size())
    RequestObject ro = new RequestObject('A')
    ro.setRestRequestMethod('POST')
    ro.setRestUrl('https://qa.alycedev.com/gifter/dashboard')
    def httpheader = new ArrayList<TestObjectProperty>()
    httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'))
    httpheader.add(new TestObjectProperty('Accept', ConditionType.EQUALS, 'application/json'))
    for (Cookie currentCookie : totalCookies) {
        httpheader.add(new TestObjectProperty('Cookie', ConditionType.EQUALS, 'domain='+currentCookie.getDomain() + '; '+currentCookie.getName() + '=' + currentCookie.getValue() + '; expires='+currentCookie.getExpiry() + '; Max-Age=7200; path=/;'))
    }
    ro.setHttpHeaderProperties(httpheader)
    def body = '{"_token": "' + GlobalVariable.G_api_oauth.csrfToken + '","use_credits": ' + GlobalVariable.G_product.price + ',"use_payment": 0.00,"currency_id": 1,"total_price": ' + GlobalVariable.G_product.price + ',"payment_data" : null,"gift_send_data": "{"id":' + GlobalVariable.G_gift.id + ',"product_id":' + GlobalVariable.G_product.id + ',"total_price":' + GlobalVariable.G_product.price + ',"send_now":true,"schedule_at":"","send_type":"hwcard","gifter_company":"Apple","giftee_company":"Sony","from":null,"gifter_address":{"country":{"id":1,"name":"United States","code":"US","image":""},"country_id":1,"address":"Address","address2":"Address 2","city":"City","state":"State","zipcode":"123321"},"giftee_address":{"country":{"id":1,"name":"United States","code":"US","image":""},"country_id":1,"address":"Address","address2":"Address 2","city":"City","state":"State","zipcode":"123321"},"message_to_giftee":{"id":1,"default":1,"message":"Messages subject + 10 characters.","subject":"Something for your time","name":"Something for your time"},"prospect":{"capture_date":true,"capture_email":true,"capture_phone":true,"capture_question":false,"capture_affidavit":false,"gifter_affidavit":"","gifter_question":""},"delivery_method_data":{"type":"branded_box"}}"}'
    ro.setBodyContent(new HttpTextBodyContent(body, 'UTF-8', 'application/json'))

    WebUI.comment(ro.activeProperties.toArray().toString())
    try{
        def response = WSBuiltInKeywords.sendRequest(ro)
    }
    catch(Exception ex) {
        println(ex.detailMessage)
        println(ex.stackTraceDepth.toString())
    }
}

标签: apiautomated-testsruntime-errorwebrequestkatalon-studio

解决方案


推荐阅读