UE5 UC++流式请求 || Varest流式调用Coze(但一次性回复,不太推荐)

++文章仅供参考。C++调用的是公司后台的接口,博主未尝试用C++调用Coze的接口,需要补充更多的代码。++

------------

C++

cpp 复制代码
#include "HttpModule.h"
#include "HttpManager.h"
#include "Http.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyCustomEventDelegate, FString, Str1);
public:
	UPROPERTY(BlueprintAssignable, Category = "MyHTTP2")
		FMyCustomEventDelegate StreamingRequestBindEvent;
cpp 复制代码
void UBPC_CJiaJia_streamRequest_V01::StartStreamingRequest(const FString& Url, const FString& Question)
{
	TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetVerb("GET"); // 设置请求方法为GET
	HttpRequest->SetURL(Url); // 设置请求的URL
	HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("text/event-stream")); // 设置请求头

	// 请求中返回
	//HttpRequest->OnRequestProgress().BindLambda([this](FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) {
	//		FString ContentString = Request->GetResponse()->GetContentAsString();
	//		this->StreamingRequestBindEvent.Broadcast(ContentString);
	//	}
	//);

	// 请求结束返回
	HttpRequest->OnProcessRequestComplete().BindLambda([this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
		if (bWasSuccessful) {
			this->StreamingRequestBindEvent.Broadcast(Response->GetContentAsString());
		}
		}
	);

	// 开始处理请求
	HttpRequest->ProcessRequest();
}

请求时,网址+?+参数

Varest

参考网址
扣子 - 开发指南 (coze.cn)创建会话
扣子 - 开发指南 (coze.cn)发起会话

++不太推荐原因是,Varest好像只能做到整段返回++

创建会话

对话

相关推荐
一枝小雨1 小时前
【C++】list 容器操作
开发语言·c++·笔记·list·学习笔记
HMBBLOVEPDX1 小时前
C++(继承和多态)
开发语言·c++·继承和多态
愚润求学2 小时前
【贪心算法】day8
c++·算法·leetcode·贪心算法
平生不喜凡桃李2 小时前
C++ 异常
android·java·c++
小伟童鞋2 小时前
c++中导出函数调用约定为__stdcall类型函数并指定导出函数名称
开发语言·c++
维C泡泡2 小时前
C++初认、命名规则、输入输出、函数重载、引用+coust引用
开发语言·c++
青草地溪水旁2 小时前
设计模式(C++)详解——建造者模式(2)
c++·设计模式·建造者模式
郝学胜-神的一滴3 小时前
深入探索 C++ 元组:从基础到高级应用
开发语言·c++·stl·软件工程
量子炒饭大师3 小时前
收集飞花令碎片——C语言关键字typedef
c语言·c++·算法
宁静致远20214 小时前
【C++设计模式】第五篇:装饰器模式
c++·设计模式·装饰器模式