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

创建会话

对话

相关推荐
漫游者Nova6 分钟前
虚幻引擎Unreal Engine5恐怖游戏设计制作教程,从入门到精通从零开始完整项目开发实战详细讲解中英字幕
ue5·游戏引擎·虚幻·游戏开发完整教程·恐怖游戏开发
ruanjiananquan9917 分钟前
c,c++语言的栈内存、堆内存及任意读写内存
java·c语言·c++
持梦远方1 小时前
C 语言基础入门:基本数据类型与运算符详解
c语言·开发语言·c++
江理不变情1 小时前
图像质量对比感悟
c++·人工智能
apocelipes2 小时前
记一次ADL导致的C++代码编译错误
c++·开发工具和环境
Code Warrior3 小时前
【每日算法】专题五_位运算
开发语言·c++
OneQ6668 小时前
C++讲解---创建日期类
开发语言·c++·算法
Coding小公仔10 小时前
C++ bitset 模板类
开发语言·c++
菜鸟看点10 小时前
自定义Cereal XML输出容器节点
c++·qt
悲伤小伞12 小时前
linux_git的使用
linux·c语言·c++·git