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好像只能做到整段返回++

创建会话

对话

相关推荐
nazisami23 分钟前
红黑树详解
数据结构·c++·面向对象·红黑树
kyle~30 分钟前
RTPS(Real-Time Publish-Subscribe)---DDS的传输协议
c++·机器人·ros2
TIEM_6940 分钟前
C++ vector容器全面解析:从入门到精通
开发语言·c++
Irissgwe41 分钟前
c++多态
开发语言·c++·多态
lingran__42 分钟前
C++_类和对象(上)
开发语言·c++
lzh200409191 小时前
手搓一个简易 Linux 进程池:巩固进程知识
linux·c++
basketball6161 小时前
C++ 的 const 相关知识点总结
开发语言·c++
阿文的代码库1 小时前
对于C++中push_back的原理介绍与分析
开发语言·c++
枕星而眠1 小时前
C++ 核心语法精讲:auto / 模板 / 命名空间 / 动态内存 从用法到面试
开发语言·c++·面试
yoyo_zzm1 小时前
六大编程语言核心差异全解析
c语言·c++·spring boot·php